File to array: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Added in r18740 |
||
Line 8: | Line 8: | ||
|function1.param2.default= | |function1.param2.default= | ||
|function1.param1.description=Path to the text file | |function1.param1.description=Path to the text file | ||
|description=The returned value is actually a map of strings, one string for each line. Like <code>[[file_to_map|file_to_map()]]</code>, empty lines and those starting with a <code>#</code> are ignored. | |description=<p>The returned value is actually a map of strings, one string for each line. Like <code>[[file_to_map|file_to_map()]]</code>, empty lines and those starting with a <code>#</code> are ignored.</p> | ||
<p>This function was added in [https://kolmafia.us/threads/18740-add-string-int-file_to_array-string-filename.22964/ r18740].</p> | |||
|code1={{CodeSample | |code1={{CodeSample | ||
|title=Code Samples | |title=Code Samples |
Revision as of 05:05, 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}`);
}