I am writing an application that must generate a plain text file with fixed-sized columns.
My current code is:
Dim MyFilePath As String = Path & FILE_PREFIX & FileNr & ".TXT"
IO.File.Delete(MyFilePath)
Dim FileStr As New IO.StreamWriter(MyFilePath, False, <ENCODER HERE>)
Do While r.Read
FileStr.WriteLine(r("TXTLine"))
Loop
FileStr.Close()
r.Close()
My problem is that I have some special characters like: "ñ", "à", etc., and I can't find the right encoding.
- If I use the default, then it replaces "ñ" with two characters.
- If I use ASCII then all special characters end up as: "?"
- If I use UTF-8 then all text is OK, but it adds a "ÿ" in the first byte of the file.
I need the special characters to be written in the textfile just as they came in the datareader. And I can't have extra characters added because columns are of fixed lenght...
What could I do?