Vely logo Empower C
install     tutorials     examples     documentation     license     about

11.0.11 released on Jul 25, 2022

read-line



PURPOSE:


Read text file line by line in a loop.

SYNTAX:


read-line <file> to [ define ] <line content> [ status [ define ] <length/status> ] [ delimiter <delimiter> ]

<any code>

end-read-line


DESCRIPTION:


read-line starts the loop in which a text <file> is read line by line into <line content> (which can be created with "define" clause if it doesn't exist), with end-read-line ending this loop. Once the end of file has been reached, or an error occurs, the loop exits. The length of a text line can be obtained with optional <length/status>, which will be VV_ERR_READ if there is an error in reading file, or VV_ERR_OPEN if file cannot be opened, or VV_OKAY if end-of-file has been reached. Check <length/status> variable within the loop to obtain the length of the currently read-in line, or after the loop for successful completion or an error condition.

Buffer allocated for each line read may or may not be reused with each iteration. For that reason, if you want to save read-in lines for use beyond the code between read-line and end-read-line, save a copy of it using copy-string.

<delimiter> separates the lines in the file, and is by default new line, however it can be any character (note that it is not a string, but a single character).

Each line is null-terminated and new line (or a <delimiter>) remains if it was present (last line may not have it). There is no limit on line length, and Vely will automatically adjust the size of <line content> to accommodate the line length.

<file> can be a full path name, or a path relative to the application home directory (see vv).

Use standard C break and continue statements to exit and continue the loop.

EXAMPLES:


To read a text file line by line, and display as a web page with line breaks:
read-line "/home/user/dir/file" to define one_line status define len
    @Line length is <<p-num len>>, line is <<p-web one_line>><br/>
end-read-line

To read a text file delimited by "|" character:
read-line "/home/user/dir/file" to define one_line status define len delimiter '|'
...


SEE ALSO:


Files ( file_uploading   copy-file   delete-file   file_storage   stat-file   lock-file   uniq-file   read-file   read-line   rename-file   temporary_file   unlock-file   write-file  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. This web page is licensed under CC-BY-SA-4.0.