How can I convert ANSI to OEM in VB.net ?

J

Jay B. Harlow [MVP - Outlook]

Nicksop,
Remember that when you read a file into a string it is converted from the
encoding in the file to Unicode, that when you write it is converted from
Unicode to the encoding in the file.

You can use System.Text.Encoding.Default to get the current Windows ANSI
Code page encoding object. You can use System.Text.Encoding.GetEncoding to
get a specific code page (such as an OEM one).

You can use the
System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage to get
the current OEM code page.

Imports System.IO
Imports System.Text
Imports System.Globalization


Dim input As New StreamReader(inputPath, Encoding.Default)
Dim output As New StreamWriter(outputPath, False,
Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage))

Dim line As String

line = input.ReadLine()
Do Until line Is Nothing
output.WriteLine(line)
line = input.ReadLine()
Loop
input.Close()
output.Close()

Hope this helps
Jay
 
G

Guest

Thank you very much Jay,

I havent'nt thought that solution !!


Thank you very much for your time!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top