Results 1 to 2 of 2

Thread: [RESOLVED] Text Encoding

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Resolved [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
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Text Encoding

    My bad.
    The reader should read as Encoding.Default and not as UTF-8
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width