Failed to read special char from .txt file RRS feed

  • Question

  • Hi,

    I am trying to read some lines from a text file but a specific char fails

    Line in textfile

    Pipe ø<1> x <2> - lg. <3>mm

    Returned string after readin

    Pipe �<1> x <2> - lg. <3>mm

            Dim oTemplateStrings() As String = System.IO.File.ReadAllLines(oTemplatesPath)

    How can I read the diameter sign correct?

    Wednesday, May 16, 2018 1:26 PM

All replies

  • You'll need to use the other overload of ReadAllLines() that takes an encoding parameter and pass the encoding that matches the source file (probably Unicode or UTF32).

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, May 16, 2018 1:36 PM
  • Hi mechanicalEngineer,

    You can try the following code:

     Dim inputFile As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("D:\Testfile\test7.txt", System.Text.Encoding.Default)
            Dim str1 As String = inputFile.ReadToEnd()

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, May 17, 2018 2:02 AM