Home All Groups Group Topic Archive Search About

Importing Text File With Diacritical Marks

Author
19 Jun 2006 6:15 PM
BostonNole
Refer to MS article Q98999 for an explanation of Diacritical Marks.

When a line from a flat text file is imported from a file using the
StreamReader, any character that has a Diacritical Mark is dropped.

Sample Code:
        Dim fs As FileStream
        Dim sr As StreamReader

        Try
            fs = New FileStream("c:\temp\badrecords.txt",
FileMode.Open, FileAccess.Read)
            sr = New StreamReader(fs)

            Dim line As String = sr.ReadLine()
            Do While Not line Is Nothing

                Debug.WriteLine(line.ToCharArray())

                line = sr.ReadLine()

            Loop

            MessageBox.Show("Done")

        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Err.Clear()

        Finally
            If Not sr Is Nothing Then
                sr.Close()
                sr = Nothing
            End If
            If Not fs Is Nothing Then
                fs.Close()
                fs = Nothing
            End If

        End Try

Author
19 Jun 2006 8:04 PM
GhostInAK
Hello BostonNole,

Figure out what encoding scheme you are using (most likely UTF-8 or Unicode).
Then use the appropriate encoding when reading the file (your stream reader
will include and overloaded ctor which accepts an Encoding parameter).

-Boo

Show quoteHide quote
> Refer to MS article Q98999 for an explanation of Diacritical Marks.
>
> When a line from a flat text file is imported from a file using the
> StreamReader, any character that has a Diacritical Mark is dropped.
>
> Sample Code:
> Dim fs As FileStream
> Dim sr As StreamReader
> Try
> fs = New FileStream("c:\temp\badrecords.txt",
> FileMode.Open, FileAccess.Read)
> sr = New StreamReader(fs)
> Dim line As String = sr.ReadLine()
> Do While Not line Is Nothing
> Debug.WriteLine(line.ToCharArray())
>
> line = sr.ReadLine()
>
> Loop
>
> MessageBox.Show("Done")
>
> Catch ex As Exception
> MessageBox.Show(ex.Message)
> Err.Clear()
> Finally
> If Not sr Is Nothing Then
> sr.Close()
> sr = Nothing
> End If
> If Not fs Is Nothing Then
> fs.Close()
> fs = Nothing
> End If
> End Try
>