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!

Substring formula 1

Status
Not open for further replies.

hanchilicious

Programmer
May 23, 2002
156
GB
Hi!

I have this string that looks like

xxx*yyyyy*zz*aaaaaaa*b*cccc*dddd*

The string length may vary (but is unlikely to exceed 254 characters).

The asterisks are delimiters, and I need to assign everything that is between the asterisks to different variables.

For example:

stringvar x := mid({string},1,instr({string},'*')-1)

So x = 'xxx', y = 'yyyyy', z = 'zz', etc.

I would need to do the same thing for stringvar y and onwards, but, whilst I can find the starting position for that variable, how can I tell it when to stop?

stringvar y := mid({string},instr({string},'*')+1,<length of field between 1st and 2nd chars here>)

An array is probably what I need to use here but I seem to be having some trouble in getting that to work. Can anyone give me an idea of how to achieve this?

Thank you!

<H>
 
You can use a formula like this:

stringVar Str := &quot;xxx*yyyyy*zz*aaaaaaa*b*cccc*dddd*&quot;;
stringVar array Sp := [&quot;&quot;];
//
Sp:=Split (Str, &quot;*&quot;);

Sp[6] // Formula return 5 Array element cccc

This will place the data between the * into a string array. If you need to know how many elements in the array use the UBound(array) function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top