is it possible to write more than one line into file?
Moderator: Martin
-
- Posts: 19
- Joined: 16 Jun 2018 21:17
is it possible to write more than one line into file?
Hi, I'm looking for solution to write more than one line (multiple variables one for each line) to file. I didn't figure out if there is possibility to manage this with script. There is action "Write to File", but for me it seems only to write one line to file.
Re: is it possible to write more than one line into file?
What are multiple variables example? Do they belong to the same group of data?
List and listformat
The best way to write multiple lines in one go is to use list variable. You can add the variable needed and later when write to file, use the listformat. Example
In the write to file action, put this as the text
{write,listformat}
It will create the text as
Most of the time, the data is uniform, so we can simply just use addElement() instead. Example concept from my battey logger flow. Each periodic check will get some information and add it to a global variable list type (which I have created before)
After adding to the glovar for the whole charging session, I can then export the logged variable from list to a string using listformat in the Write to File Action
{global_battery_log,listformat}
The result is something like this.
Other concept can be concatenate the variable as you go. You can start from blank variable and concatenate each one as you continue down the script.
Will show you
List and listformat
The best way to write multiple lines in one go is to use list variable. You can add the variable needed and later when write to file, use the listformat. Example
Code: Select all
a = "The answer to the universe is 42";
b = "1 + 2 = 3";
c = "abcdefghi";
write = newList(a, b, c);
{write,listformat}
It will create the text as
Uniform dataThe answer to the universe is 42
1 + 2 = 3
abcdefghi
Most of the time, the data is uniform, so we can simply just use addElement() instead. Example concept from my battey logger flow. Each periodic check will get some information and add it to a global variable list type (which I have created before)
Code: Select all
row = "{triggertime}\t{battey_level}\t{battery_charger_counter}\t{battery_voltage}\t{battery_current_now}\t{battery_temperature}\t{battery_status}";
addElement(global_battery_log, row);
{global_battery_log,listformat}
The result is something like this.
Concatenate as you go1529025661869 1 160233 3574 -1523436 380 2
1529025667857 1 163215 3574 -1991209 380 2
1529025673866 1 166583 3574 -1985838 380 2
1529025679865 1 169920 3574 -1944334 380 2
Other concept can be concatenate the variable as you go. You can start from blank variable and concatenate each one as you continue down the script.
Code: Select all
msg = "";
a = "Hello World";
msg = msg + a + "\n";
b = "This is my first sentence";
msg = msg + b + "\n\n";
c = "===============";
msg = msg + c;
Hello World
This is my first sentence
===============
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
-
- Posts: 19
- Joined: 16 Jun 2018 21:17
Re: is it possible to write more than one line into file?
That works fine, thanks!