Readln from a text file

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Readln from a text file

Post by ZSasha » 27 Mar 2014 20:26

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Readln from a text file

Post by Martin » 28 Mar 2014 11:04

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

Locked