From fe57f382c8af2c3eecc6690ff693cb1ac547a65f Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:59:56 +0200 Subject: [PATCH] Update 599-file-tsave.markdown --- _build/reference/599-file-tsave.markdown | 33 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/_build/reference/599-file-tsave.markdown b/_build/reference/599-file-tsave.markdown index 5a00e1c3..caa48e88 100644 --- a/_build/reference/599-file-tsave.markdown +++ b/_build/reference/599-file-tsave.markdown @@ -2,31 +2,42 @@ > TSAVE file, var -Writes an array to a text file. Each array element is a text-line. +Writes the array or string `var` to the text file `file`. Each array element is a text-line in the file. Every line of the string will be one line in the text file. Use `\n` in the string to separate lines. +See TLOAD for loading data from a text-file. -* file - A string expression that follows OS file naming conventions. -* var - An array variable or a string variable. Expressions are not allowed. - +### Example 1: Save an array ``` ' Create an array with some data -DIM A A << 1 A << "test" A << 2 - -print A +print A ' Output: [1,test,2] ' Save the array. This will create the file myfile.txt in ' the same directory as your BASIC file tsave "myfile.txt", A -' Create a second array for loading -dim B - ' Load the file tload "myfile.txt", B +print B ' Output: [1,test,2,] +``` + +### Example 2: Save a string + +``` +' Create a string with some data +A = "line 1\nline 2\nline 3" +print A ' Output: line 1 + ' line 2 + ' line 3 + +' Save the string. This will create the file myfile.txt in +' the same directory as your BASIC file +tsave "myfile.txt", A -print B +' Load the file +tload "myfile.txt", B +print B ' Output: [line 1,line 2,line 3] ```