Re: How determinate if there no symbol in a string.

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: Regular Expression Function
    ... I want a regular expression to compare sentences and then rate them as ... I have an array with a list of other phrases like so... ... characters will throw things off. ... "In an hour the system will go down for maintenance". ...
    (alt.php)
  • Re: Regular Expression Function
    ... I want a regular expression to compare sentences and then rate them as ... I have an array with a list of other phrases like so.. ... These will be stripped from the input first. ... characters will throw things off. ...
    (alt.php)
  • Re: How to best parse a CSV data file and do a lookup in C?
    ... > and build an array for each line seperating on the commas. ... that you either change its type to "static char" (otherwise the ... making fscanfread a maximum number of 128 characters as long ... that must be a comma or a newline. ...
    (comp.lang.c)
  • Re: Sorry, newbie question about generating a random string
    ... string grows to a max of 10 characters. ... The real problem is that you are not terminating the string. ... string is an array of characters ending in a null character, ... char myChar; ...
    (comp.lang.c.moderated)
  • Re: regex
    ... I suppose pedantry has its place. ... I was simply talking about looping through the characters in the ... array of char. ...
    (microsoft.public.dotnet.languages.csharp)