-
[RESOLVED] Text Encoding
Hi!
I was trying to read some file that is encoded with UTF-8 and save it as UTF-16 (Unicode) but it seems not to be fully working as all accents seem to vanish or are encoded to something that can not be read.
Here is the code that i am using:
Code:
Public Function GetFileContents(ByVal FullPath As String, Optional ByRef ErrInfo As String = "") As Object
Dim strContents As String
Dim objReader As StreamReader
Try
objReader = New StreamReader(FullPath, Encoding.UTF8)
strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
Return ErrInfo
End Try
End Function
Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean
Dim bAns As Boolean = False
Dim objReader As StreamWriter
Try
objReader = New StreamWriter(FullPath, False, System.Text.Encoding.Unicode)
objReader.Write(strData)
objReader.Close()
bAns = True
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
Return bAns
End Function
-
Re: Text Encoding
My bad.
The reader should read as Encoding.Default and not as UTF-8