Products Resources Support About Us

Field function delimiter argument

Has there ever been an implementation of the field function in the various flavors of Pick/UniBasic etc. that would operate on a delimiter of more than one character? The documented implementations I can find stipulate one character as the delimiter argument and if the delimiter is presented with more than one character, the first character of the delimiter string is used. I am asking this because there are many instances in the commercial and custom software I maintain where I see attempts to use a multi-character delimiter with the field statement. It seems programmers were using it expecting a different result than is currently happening.

Ignoring UniVerse and National Language Support (NLS) which supports multi-byte characters (which does not seem relevant to the question), I am not aware of FIELD function supporting multI-character data delimiters, though it is possible to code an equivalent. Here is an example based upon “XY” as the delimiting string value:

001: STRING.VAR=“XXABCXYDEFXYGHIXXJKLXYMNO”
002: CRT “Extraction based on ‘XY’ - really uses just ‘X’”
003: CRT STRING.VAR
004: CRT FIELD(STRING.VAR,“XY”,3)
005: CRT
006: CRT “Extraction based on ‘XY’ using a coding solution”
007: STRING.WORK=CHANGE(STRING.VAR,“XY”,@FM)
008: CRT STRING.WORK
009: CRT STRING.WORK<3>

And in execution:

Extraction based on ‘XY’ - really uses just ‘X’
XXABCXYDEFXYGHIXXJKLXYMNO
ABC

Extraction based on ‘XY’ using a coding solution
XXABC■DEF■GHIXXJKL■MNO
GHIXXJKL

By using a work variable, the original variable is left intact, though this step can be omitted if not needed. The CHANGE function can change multi-character strings so we replace the chosen delimiter string of “XY” with a field mark in this example to make extraction simple, though any delimiter could have been chosen.

Hopefully this helps.