File to array: Difference between revisions
Jump to navigation
Jump to search
Added in r18740 |
No edit summary |
||
Line 23: | Line 23: | ||
|moreinfo= | |moreinfo= | ||
}} | }} | ||
|see_also={{SeeAlso|file_to_map|map_to_file}} | |see_also={{SeeAlso|buffer_to_file|file_to_array|file_to_map|map_to_file}} | ||
|{{{1|}}} | |{{{1|}}} | ||
}}</onlyinclude> | }}</onlyinclude> | ||
[[Category:Miscellaneous Functions]] | [[Category:Miscellaneous Functions]] |
Revision as of 05:33, 21 December 2020
Function Syntax
string [int] file_to_array( string filename )
- Reads data from a text file and returns a map of strings containing each line.
- filename: Path to the text file
The returned value is actually a map of strings, one string for each line. Like file_to_map()
, empty lines and those starting with a #
are ignored.
This function was added in r18740.
Code Samples
Reads a data file into a map of strings and prints each line
string [int] lines = file_to_array("mydata.txt");
foreach line_no, line in lines {
print(`{line_no}: {line}`);
}