Problems with streamread

I discovered a really great problem when using streamread function in visual....
The special characters, such as a, e, i, o, u, €,.. etc are not even readed from the file i try to read from... so, a line like this:

I want to be a great programmer

is transformed to this:

I want t be great programmer


Does anybody know why this happens and also if there is some other way to read and write from simple text files that dont reperesent this problem

Thanks


Answer this question

Problems with streamread

  • fornol

    Change the StreamReader.Encoding property.


  • sgaap

    I have my streamreader:

    srInput = New StreamReader("C:\test.txt")

    How can i modify the streamreader (srInput) to make it have an unicode (for example) encoding


  • RichardM_UK

    Use the StreamReader(String, Encoding) constructor. For example:
    srInput = New StreamReader("C:\test.txt", System.Text.Encoding.UTF8)



  • Xigorph

    Jeez, don't give up so quick. Where do you live and what application did you use to write the file



  • AntonioMaia1

    Thanks nobugz, finally i did this:

    srOutput = New StreamWriter([file_path], False, System.Text.Encoding.GetEncoding(1252))
    srInput = New StreamReader([file_path], System.Text.Encoding.GetEncoding(1252))

    And it works fine already.
    Im spanish and the file is a txt database. Is just a plain txt file, but contains symbols such as a e i o u n and € (Can contain many others as it can have 50.000+ registers), but, as i said, it already seems to work fine.. but i am still thinking in inmplementing an encoding selector for the program, adding this encoding, unicode, utf8.. etc...

    Thanks again

  • ChrisHelt

    Please, that is really helpful, but im a bit lost, im sorry i have to ask you for more accurate information. I really thank your help.

  • ebence

    How can i guess the encoding i need
    I know is not utf8, neither unicode.......

    Anyway, really thank you for the help !!!

  • Orange_Oli

    Yes, don't use UTF8, use an encoding that matches the encoding of the characters in your file...


  • Albert_Khor

    I put this before the class starts:

    Imports System.Text

    Then i did this:

    srInput = New StreamReader("C:\test.txt", System.Text.Encoding.UTF8)

    I still get the same problem, the special chars are not processed properly

  • Jack Spade

    The Encoding property for the StreamReader needs to match the encoding of the file you're trying to read. In case of doubt, try System.Text.Encoding.GetEncoding(1250) or 28591...


  • Problems with streamread