1

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

Community
  • 1
  • 1
IEnumerable
  • 3,610
  • 14
  • 49
  • 78

2 Answers2

2

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

Example

File.ReadAllText("test.csv",System.Text.UTF8Encoding)
Tilak
  • 30,108
  • 19
  • 83
  • 131
1

Guess your unicode representation is wrong. Try this

string foo = "foo\xff";
foo.Replace('\xff',' ');
Antony Thomas
  • 3,576
  • 2
  • 34
  • 40
  • I'm not sure it's a good thing to "hack" the encoding. I think Tilak answer is better even if not perfect. Even better would be to know/understand what are all the encodings used in the OP's file transformation process. – Guillaume Nov 27 '12 at 06:18