txt files

N

Nuno Gomes

Hello,


I'm doing an application to treat txt files.

At the moment i have a problem...

My txt file have special caracters like 'á' or 'ã', but doing a debug (or
simply show a message box after read the txt) the ligne the VB transform the
special caracters in '?'.

I'm using the next code:
#################################################
Do While fx(ifx) <> ""

Dim MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx))

MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(";")

Dim ln As String()

While Not MyReader.EndOfData

Try
ln = MyReader.ReadFields()

Dim currentField As String
For Each currentField In ln
MsgBox(currentField)
Next

Catch ex As _
Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line: " & ex.Message & _
"not valid.")
End Try
End While

ifx = ifx + 1

Loop
#################################################

There's something wrong with this???...


Thank you for any help.




Nuno Gomes
 
K

kimiraikkonen

Hello,

I'm doing an application to treat txt files.

At the moment i have a problem...

My txt file have special caracters like 'á' or 'ã', but doing a debug (or
simply show a message box after read the txt) the ligne the VB transform the
special caracters in '?'.

I'm using the next code:
#################################################
Do While fx(ifx) <> ""

Dim MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx))

MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(";")

Dim ln As String()

While Not MyReader.EndOfData

Try
ln = MyReader.ReadFields()

Dim currentField As String
For Each currentField In ln
MsgBox(currentField)
Next

Catch ex As _
Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line: " & ex.Message & _
"not valid.")
End Try
End While

ifx = ifx + 1

Loop
#################################################

There's something wrong with this???...

Thank you for any help.

Nuno Gomes

Hi,
Could you change this line:
Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx))

to...

Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx),
System.Text.Encoding.Default)

and also you can set detectEncoding parameter as "True" after
System.Text.Encoding.Default as third parameter of TextFieldParser if
you need to be sure which encoding is being used.(Default is true)

Hope this helps,

Onur Güzel
 
A

Armin Zingler

Nuno Gomes said:
Dim MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx))

Pass the right encoding:


Dim MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(fx(ifx), _
System.Text.Encoding.Default)

Often it is System.Text.Encoding.Default. I don't know which encoding has
been used to write the file, so you may replace the default encoding with a
new encoding object:

System.Text.Encoding.GetEncoding(???) '???=encoding used to write the
file



Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top