I am having a problem writing a string like a word “Zürich” the output became “Z�rich”
I am using StreamReader and StreamWriter.
Anyone can help me with this.
Code: below
Imports System
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
Dim sReport As String
Dim strline As String
Dim objSR As StreamReader
Dim objSW As StreamWriter
sReport = "C:\InvalidChar1.txt"
Try
objSW = New StreamWriter(sReport)
objSR = New StreamReader("C:\InvalidChar.txt")
Do
strline = objSR.ReadLine
objSW.WriteLine(strline)
Loop While objSR.EndOfStream <> True
objSW.Close()
objSR.Close()
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Module
By default both
StreamReaderandStreamWriterwill use the UTF-8 encoding.If this is not the original encoding of the file, I’d expect to see these issues – make sure the file is a UTF-8 file.