问题描述:

I'm trying to write the content of my textbox to a txt file.

My code works fine but my error is, when I open txt file I see

writeline1writeline2writeline3

instead of

writeline1

writeline2

writeline3

my code;

result As List(Of String) = New List(Of String)

convertedText.Lines = result.ToArray()

My.Computer.FileSystem.WriteAllText(mypath & "\convertedcontent.txt", convertedText.Text, False)

Writing to .csv and many other file types work fine but I don't know how to break lines for text file.

Thanks in advance

网友答案:

I would use System.IO.File.WriteAllLines:

Dim path = System.IO.Path.Combine(mypath, "convertedcontent.txt")
System.IO.File.WriteAllLines(path, result)

Otherwise you need to append Environment.NewLine to each line, you can use String.Join:

System.IO.File.WriteAllText(path, String.Join(Environment.NewLine, result))
网友答案:

You need to add & vbCrLf to your strings (each line)

Not sure where you are getting your strings from.. but you will have to add the carrier return/Line Feed character to those strings, one at the end of every string.

Might just even loop through your array and add them there?

P.S. Some of the comments have quicker ways of getting there, but this is probably what happens behind the scenes...

for i = 0 to convertedText.Lines.count -1
  convertedText.Lines(i) += vbCrLf
next
相关阅读:
Top