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

find occurences of a character in a string 2

Status
Not open for further replies.

kenwood1

Technical User
Sep 4, 2007
6
AU
I am using CR v9

I have long text string that has the data I need separated by a ;. I would like to give each occurence of ; a position number and then use the MID formula to display them on a report.

I have used 'Instr' in my attempt, I found the first occurrence and the shortened the string this value, then found the next occurence.... and so on. This gets me the result but is very slow.
 
kenwood1,

The following will split your text up into an array:
stringvar array txt := split({table.name},";");

The following will return the number of values:
ubound(txt)

To show the values:
txt[1]
txt[2] ...

Andy
 
If you don't know how many segments there are in the field, then you should write separate formulas like this, expanding upon Andy's suggestion:

//{@segment1}:
stringvar array txt := split({table.name},";");
if ubound(txt) >= 1 then
txt[1] else
{table.name} //add the field as the default in the first formula only to account for fields without semicolons;

//{@segment2}:
stringvar array txt := split({table.name},";");
if ubound(txt) >= 2 then
txt[2]

If you want to number the segments, then change the formulas to:
//{@segment1}:
stringvar array txt := split({table.name},";");
if ubound(txt) >= 1 then
"1) "+txt[1] else
"1) "+{table.name}

//{@segment2}:
stringvar array txt := split({table.name},";");
if ubound(txt) >= 2 then
"2) "+txt[2]

Write as many formulas (or more) than the maximum number of segments.

-LB
 
Thanks andymc & lbass this was the exact solution to my problem, it worked like a dream and 100 times faster than my method. Thanks again guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top