I have a CSV file. When viewed in wordpad, there are spaces at the ends of some of the lines. When read via File.ReadAllText(filename) in C#, the spaces appear as ?. What could be causing this?
I’d like to eliminate this whitespace but using a regex doesn’t work seeing as the question marks are mucking up the data.
It could very well be that the characters displayed by Wordpad as spaces are in fact non-ASCII characters, or that the file is using an encoding that you do not expect in your C# program.
Have a look at the file in a hex editor.
If you don’t have a hex editor handy, you can use File.ReadAllBytes to read in the file as a byte array and look for byte values that are outside the range of printable ASCII values near where you are seeing question marks.