|
|
|
|
|
- Method 1: Using the fReadLine function
- Principle
- Code samples
- Method 2: Using the fLoadText function
- Principle
- Code example
How to read in a text or CSV file?
Two methods can be used to read a text or CSV file: Method 1: Using the fReadLine function Principle To read a line in a text or CSV file: - Open the file with fOpen.
- Read the line with fReadLine.
- Close the file with fClose.
Code samples - Reading a line:
// Read a simple string nFileNum is int sLineRead is string nFileNum = fOpen ("MyFile.txt", foRead) IF nFileNum <> -1 THEN // Read the line sLineRead = fReadLine(nFileNum) fClose(nFileNum) END
- Reading a data file in TXT format (import)
nFileNum is int sLineRead is string nFileNum = fOpen ("ImportProducts.txt", foRead) IF nFileNum <> -1 THEN sLineRead = fReadLine(nFileNum) // Read the 1st line WHILE sLineRead <> EOT // Check the end of file // Process the line ... // Read the next line sLineRead = fReadLine(nFileNum) END fClose(nFileNum) END
Method 2: Using the fLoadText function Principle To read a text or CSV file in a single operation: - Declare a string variable.
- Load the entire file content in memory in this variable with fLoadText.
- Process the string in memory to analyze its content.
Code example // Read a data file in TXT (import) sFileContent is string sLine is string // Load the file content in memory sFileContent = fLoadText("ImportProducts.txt") FOR EACH STRING sLine OF sFileContent SEPARATED BY CR // Process the line ... END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|