SirAudens
SirAudens

Reputation: 59

Writing a .txt file, without a extra line?

Public Sub WriteTextFile(ByVal SourceToWrite As String, ByVal LocationToWrite As String)
    Dim file As System.IO.StreamWriter
    IO.File.Delete(LocationToWrite)
    file = My.Computer.FileSystem.OpenTextFileWriter(LocationToWrite, True)
    file.WriteLine(SourceToWrite)
    file.Close()
End Sub

This is a module I made to write to a .txt file. Every time it adds a new line with null value. wouldn't really bother me but it adds but then something that only suppose to have like 3 lines in it ends up with 5000 over time, anyone know how to not add that extra line while writing file?

Upvotes: 2

Views: 4151

Answers (1)

wpwall
wpwall

Reputation: 179

file.WriteLine(SourceToWrite)

The WriteLine() function appends a newline character to its output. To avoid that, use:

file.Write(SourceToWrite)

Upvotes: 8

Related Questions