IEnumerable
IEnumerable

Reputation: 3790

Error reading a from file - Encoding issue

Im reading a CSV file that was created from MS Excel. When I open it up in notepad it looks ok, but in Notepad++ I change the Encoding from ANSI to UTF8 and a few non printed characters turn up.

Specifically xFF. -(HEX Value)

In my C# app this character is causing an issue when reading the file so is there a way I can do a String.replace('xFF', ' '); on this?

Update

I found this link on SO, as it turns out it is the answer to my question but not my problem. Link

Upvotes: 1

Views: 230

Answers (2)

Antony Thomas
Antony Thomas

Reputation: 3686

Guess your unicode representation is wrong. Try this

string foo = "foo\xff";
foo.Replace('\xff',' ');

Upvotes: 1

Tilak
Tilak

Reputation: 30688

Instead of String.Replace, Specify encoding while reading the file.

Example

File.ReadAllText("test.csv",System.Text.UTF8Encoding)

Upvotes: 2

Related Questions