Antoine Posted January 26, 2005 Posted January 26, 2005 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 Quote
Leaders dynamic_sysop Posted January 26, 2005 Leaders Posted January 26, 2005 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 Quote
Antoine Posted January 26, 2005 Author Posted January 26, 2005 @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 Quote
Antoine Posted January 27, 2005 Author Posted January 27, 2005 (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 January 27, 2005 by Antoine Quote
Antoine Posted January 27, 2005 Author Posted January 27, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.