.NET Framework - Encoding of Text Files
Asked By Samuel
04-Apr-08 06:33 AM
Hi
Currently text file that I create are UTF-8 encoded and I need ANSI encoding
how can I do that
Thank you,
Samuel
System.Text.Encoding.Default
(1)
Environment.SpecialFolder.Desktop
(1)
Encoding.Default.GetBytes
(1)
Environment.GetFolderPath
(1)
FileMode.Create
(1)
SpecialFolder
(1)
GetFolderPath
(1)
StreamWriter
(1)
rowe_newsgroups replied...
ng
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 =3D "hello, world"
Using stream As New
FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
& "/file.txt", FileMode.Create)
Dim bytes As Byte() =3D Encoding.Default.GetBytes(text)
stream.Write(bytes, 0, bytes.Length)
End Using
End Sub
End Module
/////////////
Thanks,
Seth Rowe [MVP]
Herfried K. Wagner [MVP] replied...
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.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
kimiraikkonen replied...
ng
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.
Samuel replied...
Thank you all
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.
Does anyone know how I can preserve the original characters? Thanks, Martin VB.NET Discussions System.Text.Encoding.Default.EncodingName (1) System.Text.Encoding.GetEncodings (1) Windows Mobile 5.0 (1) System.Text.Encoding.Default (1) System.IO.StreamReader (1) System.IO.StreamWriter (1) StreamWriter (1) StreamReader (1) How exactly
and the same happens. This makes no sense. Any ideas? Thanks LS VB.NET Discussions System.Text.Encoding.Default (1) System.IO.StreamWriter (1) StreamWriter (1) VB (1) Encoding (1) Click (1) FCzel (1 for that purpose: Using writer As New System.IO.StreamWriter _ ("c: \ file.txt", True, System.Text.Encoding.Default) ' Do the stuff End Using http: / / msdn.microsoft.com / en-us / library / system.text.encoding
this line: Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx)) to. . . Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx), System.Text.Encoding.Default) and also you can set detectEncoding parameter as "True" after System.Text.Encoding.Default as third parameter of TextFieldParser if you need to be sure which encoding is being
selon le codage ANSI, comme faire ? Merci d'avance Cordialement Stéphane VB.NET - French Discussions System.Text.Encoding.Default (1) System.IO.StreamWriter (1) MsgBoxStyle.Critical (1) Word (1) MonStreamReader.ReadToEnd (1) StreamWriter (1 de destination avec l'encodage souhait?, ici a. . Dim fic_dest As New StreamWriter(file_destination, True, System.Text.Encoding.Default) a. . 'D?claration du fichier source avec son encodage, ici UTF8 a. . Dim monStreamReader As
Bytearray? Ohne irgendwelche konvertierungen byte[] barray = null; string tt = "01C7" ???? Gruss Michael C# - German Discussions System.Text.Encoding.Default.GetBytes (1) Encoding.ASCII.GetBytes (1) System.Globalization.NumberStyles.HexNumber (1) System.Encoding.Unicode.GetBytes (1 statt ASCII auch andere Codierungen zur Verfügung, z.B. UniCode Hallo Michael, z.B. mit: System.Text.Encoding.Default.GetBytes("Hallo"); wobei "Encoding.Default" unter Windows normal die aktuelle Windows-ANSI Codepage nimmt