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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String parsing 1

Status
Not open for further replies.

rnd

Programmer
Jun 30, 2001
44
0
0
US
CR 9 SQL2K
I have a memo field like this:
<<value1>><<value2>><<value3>><<Value4>><<Value5>><<Valeu6>><<Value7>><<Value8>> and so on.
I want to extract every third value looping through from the beginning to the end of the string (like Value1, 4, 7, 10 etc) and display each one on a line with a hard return chr{13}, like
Value1
Value4
Value7 etc
Is it possible. I would appreciate the help.
Thanks in advance.
 
How about showing a sample of the actual field, so we can see what dividers are available between values?

-LB
 
Try something like this:

stringvar array x := split({table.memo}," ");
numbervar i;
numbervar j := ubound(x);
stringvar y := "";

for i := 1 to j step 3 do(
y := y + x + chr(13));
y

Be sure to format the formula to "can grow".

-LB
 
Oops, forgot to mention that in the split function you should replace the space in " " with your actual divider.

-LB
 
Yep, it's possible.

So theses values (you should state the data types and show examples, not use non-technical examples and terms) are within these characters <<>>?

If so, try:

whileprintingrecords;
stringvar array MyValues := split("<<Hi>><<there>><<my>><<friend>><<how>><<are>><<you>>",">>");
Stringvar OutString:="";
numbervar counter;
For counter := 3 to ubound(MyValues) step 3 do(
OutString:=outstring+replace(MyValues[counter],"<<","")+chr(13)
);
OutString

If you didn't mean to use <<>>, replace it with what makes sense and please be accurate in future posts.

-k
 
Ooops, change my formula to got from 1 to ubound as you don't want every 3rd value, you want the 1st and then every 3rd thereafter.

-k
 
Thanks for the super quick responses. You guys are awesome. Both formulas work. Lbass's formula still keeps the << dividers intact where as Synapsevampire's formula along with the change for the first record has rectified that through the Replace function and display exactly what I want.
Lbass those << & >> are the actual dividers. I didn't try to be tricky.
Just for other's benfit since I am using only one memo field with multiple values (concatenated with those <<>> dividers) I replaced the...
split("<<Hi>><<there>><<my>><<friend>><<how>><<are>><<you>>",">>"); to
split(Table.Field,">>");
Works perfectly.

Thanks to all.
 
Ooops. I forgot add that I modified LBass's formulas as below and it works well too:

stringvar array x := split({Table.Filed},">>");
numbervar i;
numbervar j := ubound(x);
stringvar y := "";

for i := 1 to j step 3 do(
y := replace(y,"<<","") + x + chr(13));

y
 
Yeah, our formulas are basically the same, you should see similar results.

You can simplify and speed both up with:

stringvar array x := split(replace({Table.Filed},"<<",""),">>");
numbervar i;
numbervar j := ubound(x);
stringvar y := "";
for i := 1 to j step 3 do(
y := y + x + chr(13));

This does the replace once.

-k
 
Is there a better way of giving a list of the multiple values of a parameter than useing this?


StringVar Array X := {?Customers};
NumberVar i;
NumberVar J := UBound(X);
StringVar Y := "";

for i := 1 to J step 1 do(
Y := Y + X + Chr(13));
Y

 
For parameters of string datatype, you can use the Join function:

join({?customers},", ")

If you want a return instead of a comma, use:

join({?customers},chr(13))

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top