Page 1 of 1

Readln from a text file

Posted: 27 Mar 2014 20:26
by ZSasha
Hi Martin,

Could you please implement a feature like "readln" - means read strings from a text file and automatically parse them by x10x13, so each line of text will be placed into a list[1], list[2] etc...
Not the best explanation but basically just standard readln in programming languages.

Right now I have to parse the file manually which takes quite a lot of time.

thanks.

Re: Readln from a text file

Posted: 28 Mar 2014 11:04
by Martin
Hi,

You can use function split to create a list of text lines from a file:
-action Init Variable Text File: /file.txt to file_text
-action Script: lines = split(text_file, "\\n"); (or "\\r\\n" when the text file uses the windows-style line breaks)

Local variable lines is a list and will contain an element for each line. You can access the elements using function getElement (line 1 is at list index 0):

Code: Select all

line1 = getElement(lines, 0);
line2 = getElement(lines, 1);
or using a for-loop in a script:

Code: Select all

for(line in lines)
{
  log(line);
}
Regards,
Martin