Skip to content

Commit

Permalink
Update 599-file-tsave.markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe7M authored Sep 7, 2023
1 parent b86ebe5 commit fe57f38
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions _build/reference/599-file-tsave.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```

0 comments on commit fe57f38

Please sign in to comment.