Focal Point
Dividing one input-field into several lines of output according to a given separator

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

July 01, 2004, 09:23 AM
<Stahl>
Dividing one input-field into several lines of output according to a given separator
Hi,

I have a input-field like this :

CC:5675634349,Z. Zidane,5000,00&CC:4757676439,DAVID BECKHAM,10000,00&EC:4545,FIGO&

The &-sign is to be interpreted as a separator.

Now I want to produce a output like this (3 lines for this example):

CC: 5675634349,Z. Zidane,5000,00
CC:4757676439,DAVID BECKHAM,10000,00
EC:4545,FIGO

Does anybody know how to solve this problem?
Thanks for any advice!
Stahl
July 01, 2004, 12:19 PM
<ineuxf>
Here you will find my solution using CTRAN and GETTOK:

-SET &ECHO=ALL;
-RUN

-* create a file with your test conditions: Ampersand as a delimiter
DEFINE FILE CAR
INFIELD/A80 WITH COUNTRY=
'CC: 567,Z. Zidane,5000,00&|CC: 39,DAVID BECKHAM,100,00&|EC:4545,FIGO&|';
END
TABLE FILE CAR
PRINT
COUNTRY
INFIELD
IF RECORDLIMIT IS 1
ON TABLE HOLD AS HOLDCAR
END

-* Solution with CTRAN and GETTOK
SET STYLEMODE = FIXED
SET PANEL = 145
DEFINE FILE HOLDCAR
-* Ampersand is a reserved sign for Focus Dialog Manager variables.
-* Therefore change Ampersand & to # with the CTRAN function
CHGFIELD/A80 = CTRAN (80,INFIELD,38,35,'A80');
-* pick up the string up to the next # as a new field.
FLD1/A80 = GETTOK(CHGFIELD,80,1,'#',80,'A80');
FLD2/A80 = GETTOK(CHGFIELD,80,2,'#',80,'A80');
FLD3/A80 = GETTOK(CHGFIELD,80,3,'#',80,'A80');
END
TABLE FILE HOLDCAR
"view from HOLDCAR"
PRINT
INFIELD OVER
CHGFIELD OVER
FLD1 OVER
FLD2 OVER
FLD3
BY COUNTRY NOPRINT
END
-EXIT

Result:

PAGE 1

view from HOLDCAR
INFIELD CC: 567,Z. Zidane,5000,00&CC: 39,DAVID BECKHAM,100,00&EC:4545,FIGO&
CHGFIELD CC: 567,Z. Zidane,5000,00#CC: 39,DAVID BECKHAM,100,00#EC:4545,FIGO#
FLD1 CC: 567,Z. Zidane,5000,00
FLD2 CC: 39,DAVID BECKHAM,100,00
FLD3 EC:4545,FIGO


Best regards

Udo from Germany
July 01, 2004, 12:47 PM
<Stahl>
Thanks a lot, Udo. This works fine!
Best regards
Sonja from Germany
July 01, 2004, 01:08 PM
<WFUser>
A much cleaner and easier solution would be to create master file using SUFFIX=DFIX as follows:

FILE=AMPTEST,SUFFIX=DFIX,$
SEGNAME=AMPTEST,$
FIELDNAME=DELIMITER, ALIAS=&, USAGE=A1, ACTUAL=A1 ,$
FIELDNAME= FIELD1 ,,A50 ,A50 ,$
FIELDNAME= FIELD2 ,,A50 ,A50 ,$
FIELDNAME= FIELD3 ,,A50 ,A50 ,$

Then just FILEDEF the text file and PRINT the fields using OVER AS '' if you wan them under each other.