Consultor Eletrônico



Kbase P46392: How to reformat an input file which uses a non-stantdard delimiter
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   1/26/2005
Status: Unverified

GOAL:

How to reformat an input file which uses a non-standard delimiter

GOAL:

How to read records from a file which is not delimited by Carriage Return Line Feed characters

GOAL:

How to read a file which does not have CR/LF to separate records

FIX:

i.e. using streams:

/* reformatFile.p */

DEFINE STREAM output1.
OUTPUT STREAM output1 TO "d:\wrk91d\test.out".

input from "d:\wrk91d\testdelim.txt" BINARY.

/* max record size */
def var v-in as char format 'x(3000)' INITIAL "".
DEFINE VARIABLE inputKey AS CHARACTER NO-UNDO.

repeat:
IF LASTKEY <> -2
THEN
DO:
READKEY.
inputKey = CHR(LASTKEY).
/* delimiter */
IF inputKey = "~~" THEN
DO:
DISPLAY v-in FORMAT "x(45)".
PUT STREAM output1 UNFORMATTED v-in SKIP.
v-in = "".
END.
ELSE v-in = v-in + inputKey.
END.
ELSE
DO:
DISPLAY v-in FORMAT "x(45)".
PUT STREAM output1 UNFORMATTED v-in.
QUIT.
END.
end.

OUTPUT STREAM output1 CLOSE.


/* testdelim.txt */
this~isa~test


The resulting test.out file:
this
isa
test