Advertisements
/* FParse()
Parses a delimited text file and loads it into an array. Syntax :
FParse( <cFileName>, <cDelimiter> ) --> aTextArray Arguments : <cFileName> : This is a character string holding the name of the text file to load into an array. It must include path and file extension. If the path is omitted from <cFileName>, the file is searched in the current directory. <cDelimiter> : This is a single character used to parse a single line of text. It defaults to the comma. Return : The function returns a two dimensional array, or an empty array when the file cannot be opened. Description : Function FParse() reads a delimited text file and parses each line of the file at <cDelimiter>. The result of line parsing is stored in an array. This array, again, is collected in the returned array, making it a two dimensional array FParse() is mainly designed to read the comma-separated values (or CSV) file format, were fields are separated with commas and records with new-line character(s). Library is : xHb */ #define CRLF HB_OsNewLine() PROCEDURE Main() LOCAL cTextFName := "Shakespeare.txt",; a1Line SET COLO TO "W/B" SetMode( 40, 120 ) CLS HB_MEMOWRIT( cTextFName,; "When in eternal lines to time thou grow'st," + CRLF + ; "So long as men can breathe, or eyes can see," + CRLF + ; "So long lives this, and this gives life to thee." ) aLines := FParse( cTextFName, " " ) ? ? "Text file word by word :" ? FOR EACH a1Line IN aLines AEVAL( a1Line, { | c1Word | QOUT( c1Word ) } ) NEXT ? @ MAXROW(), 0 WAIT "EOF TP_FParse.prg" RETURN // TP_FParse.Main()
Advertisements