I have two computers. Both running WinXP SP2 (I don’t really know ho similar they are beyond that). I am running MS Visual C# 2008 express edition on both and that’s what I’m currently using to program.
I made an application that loads in an XML file and displays the contents in a DataGridView.
The first line of my xml file is:
<?xml version='1.0' encoding='utf-8'?>
…and really… it’s utf-8 (at least according to MS VS C# when I just open the file there).
I compile the code and run it on one computer, and the contents of my DataGridView appears normal. No funny characters. I compile the code and run it on the other computer (or just take the published version from computer #1 and install it on computer #2 – I tried this both ways) and in the datagridview, where there are line breaks/new lines in the xml file, I see funny square characters.
I’m a novice to encoding… so the only thing I really tried to troubleshoot was to use that same program to write the contents of my xml to a new xml file (but I’m actually writing it to a text file, with the xml tags in it) since the default writing to a text file seems to be utf-8. Then I read this new file back in to my program. I get the same results.
I don’t know what else to do or how to troubleshoot this or what I might fundamentally be doing wrong in the first place.
-Adeena
I’m not sure of the cause of your problem, but one solution would be to to just strip out the carriage returns from your strings. For every string you add, just call
TrimEnd(null)on it to remove trailing whitespace:If your strings might end in other whitespace (i.e. spaces or tabs) and you want to keep those, then just pass an array containing only the carriage return character to
TrimEnd:Disclaimer: I am not a C# programmer; the second statement may be syntactically incorrect