Streamreader / Accented Character / Urgent
My code is below, and has been simplified. My problem is when the file I am reading contains an accented character the streamreader simply ignores this character. So if the line I read in was a 10 bytes line, it now only writes back out a 9 byte line. This is a huge issue as the file I am working with has to be a fixed length. I know there is some encoding that can be done to make this work, but know very little about it. I would really appreciate some help on this.
Dim LINE_HOLDER As String = ""
Dim oFILE_input As System.IO.File
Dim oFILE_output As System.IO.File
Dim oWRITE As System.IO.StreamWriter
Dim oREAD As System.IO.StreamReader
oREAD = oFILE_input.OpenText(TextBox1.Text)
oWRITE = oFILE_output.CreateText("C:\FILE.TXT")
LINE_HOLDER = oREAD.ReadLine()
While oREAD.Peek <> -1
oWRITE.WriteLine(LINE_HOLDER)
RECORD_COUNTER = RECORD_COUNTER + 1
LINE_HOLDER = oREAD.ReadLine()
End While
Re: Streamreader / Accented Character / Urgent
Why don't you read the file all at once, then split it to determine the lines?
Re: Streamreader / Accented Character / Urgent
I have to read it line by line, because based on what is in that line, I am appending info to the end of the line. I NEED to have that accented character written back out.
Re: Streamreader / Accented Character / Urgent
Where did you find the PEEK command? 1970? :D
Code:
Imports System
Imports System.IO
Module module1
Sub Main()
Dim sr As StreamReader = New StreamReader("c:\tmp\TestFile.txt", _
System.Text.Encoding.Default)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()
End Sub
End Module
The StreamReader.ReadLine method removes extended characters from the line that is being read in Visual Studio