xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

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).

Info

See also:FCreate(), FOpen(), FCharCount(), FLineCount(), FParseEx(), FParseLine(), MemoLine(), MlCount()
Category: File functions , xHarbour extensions
Source:rtl\fparse.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example reads a CSV file and displays its records
// and field data

   PROCEDURE Main()
      LOCAL aText := FPparse( "Testdata.csv" )
      LOCAL aRecord, cData

      FOR EACH aRecord IN aText     //
         ? "Record #" + CStr( HB_EnumIndex() ), ": "

         FOR EACH cData IN aRecord
            ?? cData + " "
         NEXT
      NEXT

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe