randy1200 wrote:
I'm using XmlReader to read data into a string variable
in C#. Works great! Every once in a while, I see that the
string data contains a symbol that looks like a square.
Have you checked what these characters actually are? You can get the
Unicode value by doing (int) s[i] , where s is the string and i is the
zero-indexed position of the offending character. For example, they
might be bits of Unix or Apple Mac line feeds, if your file is coming
from another platform, or they might be legitimate foreign characters
that just aren't displayed correctly in your particular font.
Any suggestions on how to filter out characters that don't
appear on a keyboard?
Again, it depends on your keyboard. You could just create a string
containing all the characters you're happy with and use a
StringBuilder to loop over the original string, copying acceptable
characters (acceptableChars.IndexOf(ch) >= 0) to a new target string.
But if all or most of the problem characters are the same one, just
use String.Replace.
Eq.