# Use saveStrings to add timestamp INTO the text File

**URL:** <https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573>\
**Category:** Coding Questions\
**Created:** [September 16, 2018, 12:16pm UTC](https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573 "2018-09-16T12:16:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![losferatos](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@losferatos](https://discourse.processing.org/u/losferatos)\
**Post date:** [September 16, 2018, 12:16pm UTC](https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573/1 "2018-09-16T12:16:52Z")

</div>

Hi guys!  
I’m trying to create a certain code generator and it works quite well.  
Cliffs:  
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:

```auto
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,  
Eric

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [September 16, 2018, 12:56pm UTC](https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573/2 "2018-09-16T12:56:07Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![losferatos](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@losferatos](https://discourse.processing.org/u/losferatos)\
**Post date:** [September 16, 2018, 1:32pm UTC](https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573/3 "2018-09-16T13:32:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)\
**Post date:** [September 16, 2018, 2:15pm UTC](https://discourse.processing.org/t/use-savestrings-to-add-timestamp-into-the-text-file/3573/4 "2018-09-16T14:15:08Z")

</div>

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.
