Many thanks for the excellent response. You gave me the tools to figure it out.
The Unicode value of the square was a 10, which is a line feed. If I just
printed my string variable to the console there was no square - I just got a
newline.
The string ultimately gets picked up by Microsoft Word. That's were the
square appeared.
While processing the string, I simply replace the lf with a cr:
string s = "bunch of characters including a line feed";
string lf = (Microsoft.VisualBasic.ControlChars.Lf).ToString();
string cr = (Microsoft.VisualBasic.ControlChars.Cr).ToString();
s = s.replace(lf,cr);
Thanks again,
--
Randy
Paul E Collins said:
randy1200 said:
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
, 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.