473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

special characters

In C# how can I check for non-numeric characters in a file?
example: if the file has !@#$%^ in it, how can I check for that and create
an error message for that file?

Nov 17 '05 #1
4 1796
JustCoding,

Do you want non-numeric characters, or that range of characters? Either
way, you will have to read through the file character by character, and then
check to see if the character is a number. You can do this by getting the
character and then calling the IsNumeric method on the character. If it
returns false, you have an error.

If the file isn't too big, and you can load it into a string, you could
also use a regular expression to do this, searching for all characters that
aren't in the range you are looking for (something like the negative of
'[0-9]*' I think, I'm not that experienced with regular expressions). If
you get a match, it is an error.

If the file is particularly large though, loading the contents into a
string will be an issue, and you will see performance suffer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JustCoding" <me@m.com> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
In C# how can I check for non-numeric characters in a file?
example: if the file has !@#$%^ in it, how can I check for that and
create an error message for that file?

Nov 17 '05 #2
I can't allow any character that is not a number or letter.
example: !@#$%^&* would be invalid
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
JustCoding,

Do you want non-numeric characters, or that range of characters?
Either way, you will have to read through the file character by character,
and then check to see if the character is a number. You can do this by
getting the character and then calling the IsNumeric method on the
character. If it returns false, you have an error.

If the file isn't too big, and you can load it into a string, you could
also use a regular expression to do this, searching for all characters
that aren't in the range you are looking for (something like the negative
of '[0-9]*' I think, I'm not that experienced with regular expressions).
If you get a match, it is an error.

If the file is particularly large though, loading the contents into a
string will be an issue, and you will see performance suffer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JustCoding" <me@m.com> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
In C# how can I check for non-numeric characters in a file?
example: if the file has !@#$%^ in it, how can I check for that and
create an error message for that file?


Nov 17 '05 #3
Hi,

You could use char.IsLetterOrDigit( char )
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"JustCoding" <me@m.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I can't allow any character that is not a number or letter.
example: !@#$%^&* would be invalid
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
JustCoding,

Do you want non-numeric characters, or that range of characters?
Either way, you will have to read through the file character by
character, and then check to see if the character is a number. You can
do this by getting the character and then calling the IsNumeric method on
the character. If it returns false, you have an error.

If the file isn't too big, and you can load it into a string, you
could also use a regular expression to do this, searching for all
characters that aren't in the range you are looking for (something like
the negative of '[0-9]*' I think, I'm not that experienced with regular
expressions). If you get a match, it is an error.

If the file is particularly large though, loading the contents into a
string will be an issue, and you will see performance suffer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JustCoding" <me@m.com> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
In C# how can I check for non-numeric characters in a file?
example: if the file has !@#$%^ in it, how can I check for that and
create an error message for that file?



Nov 17 '05 #4
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#s**************@TK2MSFTNGP14.phx.gbl...
Do you want non-numeric characters, or that range of characters? Either way, you will have to read through the file character by character, and then check to see if the character is a number. You can do this by getting the
character and then calling the IsNumeric method on the character. If it
returns false, you have an error.


"IsNumeric" is a VB function. Did you mean Char.IsNumber() ?
Althought, I think you'd want Char.IsDigit(), because IsNumber has a rather
loose definition of a number ("V" passes as it's the Roman number 5).

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 17 '05 #5

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

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
3
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
17
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
5
by: Doc | last post by:
Hello! I'm experiencing a little problem counting the number of characters in a textarea on a html page. This is the content type of my HTML document content="text/html; charset=iso-8859-1" ...
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
7
by: Trac Bannon | last post by:
When I load XML from a file into a dotNet XMLDataDocument, the UTF-8 codes are resolved but the 5 special XML entities are not. How can I force those 5 special character types to be translated?
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
0
by: AAaron123 | last post by:
Been playing with asp:changepassword and have it looking OK except that I can't elininate or change the title at the top that says "Change Your Password". It's a repeat of my pages title. ...
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...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.