Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.VisualBasic.FileIO.TextFieldParser changes ± Ascii 241 to ? Ascii 63

Tags:

.net

vb.net

ascii

I am using Microsoft.VisualBasic.Fileio.TextFieldParser to parse a CSV file that was created with Excel 2003. The parser is working great with the exception that it is converting extended ascii values to question marks! So if the file content was:

± 3
The TextFieldParser is returning
? 3

I have tried all of the encodings in the System.Text.Encoding package with no luck. I thought I had it with UTF7 but it was dropping other characters like replacing the + sign with a space.

Any help would be greatly appreciated.

like image 962
aspjim Avatar asked Dec 11 '10 00:12

aspjim


1 Answers

The Microsoft.VisualBasic.Fileio.TextFieldParser defaults to UTF8 encoding, but the text file is in the system's current ANSI encoding. Use one of the constructors that take an encoding like: TextFieldParser(string path, Encoding defaultEncoding).

You can pass in System.Text.Encoding.Default for your encoding or construct a new Encoding Object passing in a code page. The default on English Windows is 1252.

like image 100
shf301 Avatar answered Jan 04 '23 19:01

shf301