Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Experts...Help! Complicated! Instr and Split Functions

Status
Not open for further replies.

faithful1

Programmer
Sep 27, 2002
49
US
First of all, please forgive me if this makes no sense! =)

I have an input parameter that returns a string as such:
1/Santa Ana,3,6,15,29,36,11,13,14,51,52,53,54/Jim Gohl,17,18,20,21,22,23,25,26,27,33,34,35/Joe Babcock


The format is: location number(s)/Name
The list just gets longer and longer as the user chooses more names from a select list to be submitted on a form.

I would want use a formula to display:
Santa Ana Jim Gohl Joe Babcock

I figured what I could do is count the number of "/" in the string. If the number is > 0 then I want to display the names after the "/"

So far, I have tried to return the full strings after the "/" which would include all numbers. But, I get "True" as output.
What am I doing wrong?

numbervar i;
NumberVar Count1;
If (instr({?VAR_LOCATIONS},"/") > 0) then
Count1 := Count1 +1
else
Count1 := 0;

If (Count1 > 0) then
for i:=2 to (Count1 + 1) step 1 do
(Split({?VAR_LOCATIONS},"/"));

 
Hey Faithful,

I guess you're trying to return a string including integers in your current loop, as a step towards the final goal, rather than because you actually want numbers.

If I understand you correctly when I assume that you only want to return the names seperated by spaces, then try the following:
Code:
StringVar OldString;
StringVar NewString;

OldString := {@VAR_LOCATIONS};  

While Length(OldString) > 0 Do
    (
        If Not IsNumeric(Left(OldString,1)) 
        Then
            If Left(OldString,1) = '/'
            Then NewString := NewString + '  '
            Else
                If Left(OldString,1) = ','
                Then NewString
                Else
                NewString := NewString + Left(OldString,1);
        OldString:= Mid(OldString,2);
    );

NewString
...which, given the case of your example, will return "Santa Ana Jim Gohl Joe Babcock".

All the best with your report,

Naith
 
Here's another way to solve the same problem.


StringVar OldString:= "1/Santa Ana,3,6,15,29,36,11,13,14,51,52,53,54/Jim Gohl,17,18,20,21,22,23,25,26,27,33,34,35/Joe Babcock";
StringVar NewString:="";

NumberVar i;
BooleanVar InWord:= False;


for i := 1 to len(OldString)-1
do
(
if OldString[i+1] = "," and InWord = true then
// When we come across the end of the 'word', change the InWord state and add a space
( InWord := False;
NewString := NewString+" ");

if OldString = "/" then
// Start of word, change the InWord state
InWord := True;

if InWord = true then
// As we move through the 'word', add to the output string
NewString := NewString + OldString[i+1];

);

NewString Steve Phillips, Crystal Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top