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

How to extract information from a string that may vary in size

Status
Not open for further replies.

bobpv

Instructor
Sep 3, 2002
107
US
I have a string created by a formula to replace some words in the string, so it looks like this:
W~1~1~1~SHW~1~5.5~1~1~

Each of the numbers shown between the ~ can be 2 didgit, with the 5.5 also can be 2, plus one dec place.

The alpha characters (W and SHW) will always be 1 (W) or 3 (SHW).
I need to pull out each 'set' of letters or numbers into it's own field in order to use in some calculation. I can pull them out with a MID, but that will not work if the length does not remain consistant. and it will not be constant it can be
W~1~14~1~SHW~1~10.5~1~10~ as well.

Can anyone share a formula that does such a thing in order to get me started? Thanks in advance.
 
It's much simpler than you think.

whileprintingrecords;
stringvar array MyValues:=Split({table.field},"~");
stringvar array 1chars;
stringvar array 3chars;
numbervar array MyVals;
numbervar counter;
For counter := 1 to ubound(MyValues:) do(
if isnumeric(MyValues[counter]) then
(
redim preserve MyVals[ubound(MyVals)+1];
MyVals[ubound(MyVals)]:= val(MyValues[counter])
)
else
if len(MyValues[counter]) = 1 then
(
redim preserve 1chars[upbound(1chars)+1);
1chars[ubound(1chars)]:= MyValues[counter]
)
else
if len(MyValues[counter]) = 3 then
(
redim preserve 3chars[upbound(3chars)+1);
1chars[ubound(3chars)]:= MyValues[counter]
);

Now you have the 3 values seperated out into 3 arrays.

Unfortunately your post doesn't state what yuo want to do, so I can't go any further, you say "into it's own field in order to use in some calculation".

There are 2 reasons why this backfires on you, I can't provide the solution, and because you think that extracting multiple values would still be considered "A FIELD". It isn't you now have multiple values to deal with.

Anyway, this is the theory for seperating the values, hopefully this is all that you need. If not, please post what you need in it's entirety, and do so in the beginning in future posts.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top