Hi programmerteam,
1)
I'm looking for opening / reading a (ascii/txt-)file as one parameter example = {file_en_bloc}
and also I wanted to search in this {file_en_bloc} a special token (like "firstname lastname").
"scriptcodeidea" for user:
file_en_bloc = loadfile (/mnt/sdcard0/datafile.dat)
a = findcontent ({file_en_bloc}, {token})
a has to be "true" or "false"
2)
I want to open/read a file contains a list with phrases
like
phrase1
phrase2
phrase3
"scriptcodeidea" for user:
phrasefile = loadlistfile (/mnt/sdcard0/datafile.dat)
a = countlines {phrasefile}
b = random [1,a]
c = usecontentline b // as text
-----
Any hints / ideas ?
operation with files
Moderator: Martin
Re: operation with files
1) You can read a text file into a variable with the action Init Variable Text File: test.txt to file_text.
There are several functions you can use in a script to process the text.
Following functions might be useful: indexOf, lastIndexOf, length, substring, left, right, startsWith, endsWith or the regex method matches.
The help page of the script action contains a list of all available functions.
For example (in a condition Expression):
The condition will be true when the text abc is found in the text of the file.
2) First read the content of a file into a variable with action Init Variable Text File: test.txt to file_text.
Then use an action Script to split the file into lines and to select a random line:
You can display the random text using Notification on Screen: Random text is {s}
Regards,
Martin
There are several functions you can use in a script to process the text.
Following functions might be useful: indexOf, lastIndexOf, length, substring, left, right, startsWith, endsWith or the regex method matches.
The help page of the script action contains a list of all available functions.
For example (in a condition Expression):
Code: Select all
indexOf(file_text, "abc")>=0
2) First read the content of a file into a variable with action Init Variable Text File: test.txt to file_text.
Then use an action Script to split the file into lines and to select a random line:
Code: Select all
//split the text into a list of lines
lines=split(file_text, "\\n");
//pick a random element of the list and store the line in variable s
s=getRandomElement(lines);
Regards,
Martin
Re: operation with files
Hey Martin,
thanks a lot ... great !!!
Regards
thanks a lot ... great !!!
Regards