Encoding of Text Files

  • Thread starter Thread starter Samuel
  • Start date Start date
S

Samuel

Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that


Thank you,
Samuel
 
Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that

Thank you,
Samuel

IIRC System.Text.Encoding.Default maps to ANSI

///////////////////
Option Strict On

Imports System.IO
Imports System.Text

Module Module1

Sub Main()
Dim text As String = "hello, world"

Using stream As New
FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
& "/file.txt", FileMode.Create)
Dim bytes As Byte() = Encoding.Default.GetBytes(text)
stream.Write(bytes, 0, bytes.Length)
End Using
End Sub

End Module
/////////////

Thanks,

Seth Rowe [MVP]
 
Samuel said:
Currently text file that I create are UTF-8 encoded and I need ANSI
encoding how can I do that

Specify the appropriate encoding in the 'StreamWriter' object's constructor.
'System.Text.Encoding.Default' will give you the system's Windows ANSI
codepage. 'System.Text.Encoding.GetEncoding(...)' will give you a certain
Windows ANSI codepage.
 
Hi

Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that

Thank you,
Samuel

As previous posters suggested, System.Text.Encoding.Default will give
you chance of encoding your text in ANSI format. Also beware that
opening your text in notepad and saving with default encoding is done
in ANSI.
 
Thank you all

Samuel

Hi

Currently text file that I create are UTF-8 encoded and I need ANSI
encoding
how can I do that

Thank you,
Samuel

As previous posters suggested, System.Text.Encoding.Default will give
you chance of encoding your text in ANSI format. Also beware that
opening your text in notepad and saving with default encoding is done
in ANSI.
 
Back
Top