Use saveStrings to add timestamp INTO the text File


Hi guys!
I’m trying to create a certain code generator and it works quite well.
It generates a number of codes and saves them into a .txt file. Now I also want to add a specific string to the end of that file (amount of time it took to create them)

So far I only have this:

saveStrings( sample size + "_output.txt", arrayName);

This generates e.g a 25000_output.txt file I wanted, but how can I archive to put my time variable onto the first/last line of that file?

Thanks in advance,


So in order to add a line at the end of your file, you could simply add a \n to the end of the last element in your array.

arrayName[arrayName.length - 1] += "\n" + my_value;

Note: Windows uses these \r “carriage return” things for a new line, so you probably should use \r\n on Windows.


Thank you DongKingKong0 - works like a charm.
Even though I don’t really understand why there is the need for the -1.
To me, it would be logical if I’ll address the last position on the array and not the one before.


The array index of the first element is 0, the length property returns the total amount of Strings in the array. The address of the last element is length - 1, since the index of the first element is 0.