Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Problem reading textfile

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Resolved [RESOLVED] [2005] Problem reading textfile

    Hello!

    Im reading a textfile using this code:

    VB Code:
    1. Dim sReader As New IO.StreamReader(New IO.FileStream(Application.StartupPath & "\data\" & drink & ".txt", IO.FileMode.Open))
    2.         While Not sReader.Peek
    3.             TextBox1.AppendText(sReader.ReadToEnd)
    4.         End While

    But my problem is that it doesnt read "special characters" like åäö.
    so if my textfile would contain "Hellö" then all that I would get would be "Hell"

    Can this be fixed?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Problem reading textfile

    u could try reading all the bytes in the file and converting to characters.

    streamreader tends to stop on special characters.

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] Problem reading textfile

    Worked fine for me, the below code was used to test, and the special characters displayed in the messagebox...
    VB Code:
    1. Dim MyWriter As New System.IO.StreamWriter("c:\test.txt", False)
    2.         MyWriter.WriteLine("Hellö There")
    3.         MyWriter.WriteLine("This ö is a test")
    4.         MyWriter.Close()
    5.         Dim MyReader As New System.IO.StreamReader("c:\test.txt")
    6.         While MyReader.Peek <> -1
    7.             MessageBox.Show(MyReader.ReadLine)
    8.         End While
    9.         MyReader.Close()
    Maybe its perhaps the filestream you declared that is doing it?

    ***EDIT - I actually tested it with the filestream you used on the streamreader, and it still worked fine.

    Are you trying to display this in a control that may not display those characters correctly?

  4. #4

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Problem reading textfile

    thanks for the replies.
    Gigemboy:
    Im just displaying the text in an ordinary textbox.
    I tried using your read code but it gives me the same results...

    High6 could you help me with that? Coz I dont have a clue how id to that.

    Thanks guys
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Problem reading textfile

    ....
    ...I dont know what happened, but suddenly it displays special characters without any problem..
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: [RESOLVED] [2005] Problem reading textfile

    Dim reader As IO.StreamReader = New IO.StreamReader(Application.StartupPath.ToString() + "\languages.dat", System.Text.Encoding.Default)

    Now your Streamreader can read Öë

Posting Permissions

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



Click Here to Expand Forum to Full Width