Character set

Antoine

Well-known member
Joined
Aug 12, 2003
Messages
58
Location
The Netherlands
Hello,

I have a little problem when reading a file that has UTF-8 encoding. Problem is that I need ANSI to read it. Is there a possible way to tell to VB.NET that it should read as ANSI and not as UTF-8 ?

Grtz,
Antoine
 
Specify Encoding.ASCII when opening the Stream , eg:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Dim pathToUtfFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\\Text\\IUserNotification.txt"
        
        Dim sreader As New StreamReader(pathToUtfFile, Encoding.ASCII)

        While Not sreader.Peek = -1
            Console.WriteLine(sreader.ReadLine)
        End While

        sreader.Close()

    End Sub
 
@Dynamic

So in my case it would be something like the following ? (Cant test it right now will do it in the morning)

Code:
Dim MyFile as string = "E:\Test\Config.txt"
Dim sReader as new StreamReader(MyFile, Encoding.ASCII)

etc.etc

Is these things I can be a real noob in .NET :-\

Will it now read the proper characters ? I mean, for instance there was the
 
Hello,

It returns an error when I try to declare the streamreader :confused:

Code:
Dim sReader as new StreamReader .....

It gives an error on Streamreader....

Who can help me please ?

Grtz,
Antoine

[edit]
And how can I exchange the Console.Readline with my own variable ? Since it returns an error on that one also :o
Sometimes I really hate .NET
[/edit]
 
Last edited by a moderator:
Managed :)

I managed to get the following which works good but doesnt use the encoding :confused:

Code:
Imports System
Imports System.IO
...
...
        Dim TestFile As String = "E:\XML meuk\test.xml"
        Dim sReader As StreamReader = New StreamReader(TestFile)

        While Not sReader.Peek = -1
            Test = (sReader.ReadLine)
...
End While
 
Back
Top