Focal Point
Dividing a long string into several fields

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1341008331

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
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?
September 28, 2004, 12:45 AM
Piipster
If 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
cmallain
quote:
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?


------------------------------------------
last version used: v7.1; truly miss the wonderful things I did with WebFOCUS, HTML, & JavaScript.
September 19, 2007, 04:28 PM
Darin Lee
yes - 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


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
September 19, 2007, 04:41 PM
Gizmo
This is usually easy to accomplish using the GETTOK subroutine.



Windows: WF 7.6.2: SQL Server 2008 R2