From: James on
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



From: Armin Zingler on
"James" <jkklim(a)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