September 27, 2004, 12:40 PM
<Stahl>Dividing a long string into several fields
Dear all,
I want to divide a long string into several fields according to a given delimiter-string.
e.g.:
string: abc?/xyz12345?/456z?/die
delimiter string: ?/
The new fields should be like this:
f1 = xyz12345
f2 = 456z
f3 = die
(The first part "abc" can be ignored.)
What I don't know in advance is, how many parts the original string has. It can be longer or shorter than the example included her.
So I don't really know, how many new fields to define.
Any hints are highly appretiated!
Thanks a lot!
stahl
September 27, 2004, 04:22 PM
susannahsure
you're going to use the POSIT function and the SUBSTR function.
(see the Using Functions Manual. Do you have it?)
POSIT will locate the delimeter, whatever delimeter you specifcy.
SUBSTR will extract a substring from some starting position (last POSIT of the delimeter + 1) to some ending position( current POSIT of the delimeter -1).
You'll loop thru your string until POSIT is 0, meaning can't find any more.
Are you ok from here?
September 28, 2004, 12:45 AM
PiipsterIf you are manipulating the string as Dialog Manager variables the looping will be fine to tell you when to stop.
If you need the values in DEFINE fields, you are going to have to make some assumptions about the longest possible substring and the most number of occurrences of the substrings, and DEFINE enough fields to handle them all.
September 19, 2007, 03:04 PM
cmallainquote:
Originally posted by susannah:
sure
you're going to use the POSIT function and the SUBSTR function.
(see the Using Functions Manual. Do you have it?)
POSIT will locate the delimeter, whatever delimeter you specifcy.
SUBSTR will extract a substring from some starting position (last POSIT of the delimeter + 1) to some ending position( current POSIT of the delimeter -1).
You'll loop thru your string until POSIT is 0, meaning can't find any more.
Are you ok from here?
Can POSIT be done with the delimiter being a space?
September 19, 2007, 04:28 PM
Darin Leeyes - you just have to be careful of spaces in the string like the space between first and last name. it may not be a delimiter, but would be counted as one anyway
September 19, 2007, 04:41 PM
GizmoThis is usually easy to accomplish using the GETTOK subroutine.