473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String Filter for non-Standard Characters

Using Visual Studio 2005.

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.

Any suggestions on how to filter out characters that don't appear on a
keyboard? I hate to let the end-user see these square characters.
--
Randy
Aug 17 '06 #1
4 4364
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.
Aug 17 '06 #2
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" wrote:
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.
Aug 17 '06 #3
Good to hear you got it working.
string lf = (Microsoft.VisualBasic.ControlChars.Lf).ToString() ;
string cr = (Microsoft.VisualBasic.ControlChars.Cr).ToString() ;
Just for reference, a more concise and C#-ish way of representing
these characters is '\n' and '\r'.

Eq.
Aug 17 '06 #4
How about the other way around. I wrote an application where I wanted to
make use of
that square character but didn't know where it comes from - I think I know
how to use it
if I knew it's source.

Regards
Chris Saunders

"randy1200" <ra*******@newsgroups.nospamwrote in message
news:22**********************************@microsof t.com...
Using Visual Studio 2005.

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.

Any suggestions on how to filter out characters that don't appear on a
keyboard? I hate to let the end-user see these square characters.
--
Randy

Aug 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Logan | last post by:
I read in PEP 279 the following comment by GvR: "filter and map should die and be subsumed into list comprehensions, not grow more variants." Actually, I am using 'filter' and 'map' a lot in...
2
by: Thomas Philips | last post by:
To experiment with filtering, I define a function f(x,k) as follows >>> def f(x,k=2): return x%k==0 I can check that it works by typing >>> f(10,3) False Now, I try to filter a range using...
5
by: NTE | last post by:
Access 2000, My application has a main form that the users interact with. There are 2 hidden fields. When they select "filter by form" from the menu, the hidden fields become visble. Is...
2
by: comp.lang.php | last post by:
var $filterArray = array('reverse' =IMG_FILTER_NEGATE, 'edge highlight' =IMG_FILTER_EDGEDETECT, 'emboss' =IMG_FILTER_EMBOSS, 'gaussian blur' =IMG_FILTER_GAUSSIAN_BLUR, 'blur'...
2
by: emo10001 | last post by:
Hey everyone, New here and fairly new to Access programming. I'm using Access 2003 in XP SP2 I've used this site before without having to ask a question but I'm really stuck :( I have a table...
2
by: Shashank | last post by:
Hi, I am passing a tcpdump filter to a function which compiles the filter using pcap_compile and then sets it. Here is the filter, ip>=0x0000 and ip <=0xd9295a3 and ip >=0x0000 and ip...
0
by: diogenes | last post by:
"Rick Brandt" <rickbrandt2@hotmail.comwrote in news:bPnKj.456$%41.325 @nlpi064.nbdc.sbc.com: I used this approach, and it works a treat! ID In(SELECT Order_ID FROM orderitems WHERE NAME =...
1
by: jvcoach23 | last post by:
I have a custom class QBank with a public property called QBankID. I populate the ilist(to QBank). when the iList is populated, is there a way i can filter on the QBankID property for where it =...
3
by: 6afraidbecause789 | last post by:
If able, can someone please help make a Where clause that strings together IDs in a multi-select listbox AND includes a date range. I wasn’t thinking when I used the code below that strings...
1
by: CatchSandeepVaid | last post by:
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class. I have applied this filter as in Java side we have one-to-one relationship...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.