Streamreader / Accented Character / Urgent
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Streamreader / Accented Character / Urgent

  1. #1
    Join Date
    Oct 2009
    Posts
    2

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,960

    Re: Streamreader / Accented Character / Urgent

    Why don't you read the file all at once, then split it to determine the lines?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,960

    Re: Streamreader / Accented Character / Urgent

    Where did you find the PEEK command? 1970?

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center