469,917 Members | 1,474 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

converting ansi to utf8 format - is there anything wrong with it ? urgently requires help

this is a console program to convert ANSI to UTF8 format. Although in
notepad i open the source file (which is ansi), and after running the
program below, and re-open in notepad (it shows utf8 encoding), does it mean
that it has been correctly converted ?

Pls let me know what i have done wrong in conversion ...

Module Module1

Dim args As String() = Environment.GetCommandLineArgs()

Dim line As String

Const newfilename As String = "_utf8"

Sub Main()

Try

If args.Length = 2 Then

Dim sr As StreamReader = New StreamReader(args(1))

Dim SwFromFile As StreamWriter = New StreamWriter(args(1) & newfilename,
False, System.Text.Encoding.UTF8, 512)

Do

line = sr.ReadLine()

SwFromFile.Write(line)

Loop Until line Is Nothing

sr.Close()

SwFromFile.Flush()

SwFromFile.Close()

End If

Catch E As Exception

Environment.Exit(1)

Console.WriteLine("The file could not be read:")

Console.WriteLine(E.Message)

End Try

Environment.Exit(1)

End Sub

End Module

Mar 17 '06 #1
1 3380
"James" <jk****@hotmail.com> schrieb
this is a console program to convert ANSI to UTF8 format. Although
in notepad i open the source file (which is ansi), and after running
the program below, and re-open in notepad (it shows utf8 encoding),
does it mean that it has been correctly converted ?

Pls let me know what i have done wrong in conversion ...

Module Module1

Dim args As String() = Environment.GetCommandLineArgs()

Dim line As String

Const newfilename As String = "_utf8"

Sub Main()

Try

If args.Length = 2 Then

Dim sr As StreamReader = New StreamReader(args(1))


I would pass System.Text.Encoding.Default as the 2nd argument to the
constructor.
Armin

Mar 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joseph Suprenant | last post: by
2 posts views Thread by Ziver MALHASOGLU | last post: by
5 posts views Thread by scott | last post: by
reply views Thread by Alci | last post: by
9 posts views Thread by Michael Goerz | last post: by
18 posts views Thread by Dirk Hagemann | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.