### File2String and String2File

Examples on how to read the content of a textfile to a string and how to write the content of a string to a file.
'Read the content of a textfile to a string.
'A list and stringbuilder is used to ensure proper CRLF handling.
'Returns File content as string or error message
'Example:fx.Clipboard.SetString(File2String(File.DirApp, "myfile.txt"))
`Private Sub File2String(folder As String, filename As String) As String
Dim result As String = ""
Dim sb As StringBuilder
sb.Initialize
Try
Dim l As List = File.ReadList(folder,filename)
For i = 0 To l.Size - 1
sb.Append(l.Get(i) & CRLF)
Next
result = sb.ToString
Catch
result = LastException.Message
End Try
Return result
End Sub`
'Save a string to a textfile
`Private Sub String2File(folder As String, filename As String, content As String)
Dim fc As FileChooser
fc.Initialize
fc.InitialDirectory = folder
fc.InitialFileName = filename
fc.Title = "Save File"
Dim f As String = fc.ShowSave(MainForm)
If f.Length = 0 Then Return
Try
File.WriteString(getFilePath(f), getFileName(f), content)
Catch
Log("Save File Error: " & LastException.Message)
End Try
End Sub`

Changed: , Category: Strings, File: T6C255M1849.htm, ID: 1849