Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

Specify Encoding.ASCII when opening the Stream , eg:

   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

Posted

@Dynamic

 

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

 

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 � sign in the file (ALT+0128), and it gave me back something like "â,◙" for this very �-sign :)

 

Thanks allready

 

Grtz,

Antoine

Posted (edited)

Hello,

 

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

 

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]

Edited by Antoine
Posted

Managed :)

 

I managed to get the following which works good but doesn't use the encoding :confused:

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...