Re: How determinate if there no symbol in a string.
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Sat, 16 Dec 2006 19:49:01 -0000
Flo 'Irian' Schaetz <iryan@xxxxxx> wrote:
And thus, Ignacio Machin ( .NET/ C# MVP ) spoke...
You do not really need to use regular expression, all you have to do is use
String.IndexOfAny( new char[] { '#', ',' .......... } );
it will return -1 if no char from the array was found
Depends on what he wants to do... If he ONLY wants to allow alphanumeric
characters, I would use a regular expression - because then your char
array would become rather long. If the number of forbidden chars is
limited, I would use your way...
Well, using your suggestion of ^[0-9a-zA-Z] knocks out several
potentially valid characters - what about a letter with an accent on?
If I *were* to use a regular expression, I'd probably use the character
classes rather than specific letters. If I didn't want to use regular
expressions, I'd iterate over the characters and use
Char.IsLetterOrDigit etc.
Of course, we don't have a rigorous definition of what the OP really
wants - what counts as a symbol in his terminology.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- How determinate if there no symbol in a string.
- From: ad
- Re: How determinate if there no symbol in a string.
- From: Flo 'Irian' Schaetz
- Re: How determinate if there no symbol in a string.
- From: ad
- Re: How determinate if there no symbol in a string.
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: How determinate if there no symbol in a string.
- From: Flo 'Irian' Schaetz
- How determinate if there no symbol in a string.
- Prev by Date: Re: Printing with Dot Matrix Printer by C#?
- Next by Date: Re: read lock needed?
- Previous by thread: Re: How determinate if there no symbol in a string.
- Next by thread: Re: How determinate if there no symbol in a string.
- Index(es):
Relevant Pages
|