Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

check string in c

Name: Anonymous 2009-05-24 9:14

what the fast way to check that string contain only characters within some set like "a-z0-9"?

Name: Anonymous 2009-05-25 16:32

>>80
All right, this code should actually *work*:

is_inset(char*s){while(*s&&*s>'/'&*s<':'|*s>'`'&*s<'{')++s;return!*s;}

Name: Anonymous 2009-05-25 16:35

is_inset(char*s){while(*s&&*s>47&*s<58|*s>96&*s<123)++s;return!*s;}

Name: Anonymous 2009-05-25 16:37

is_inset(char*s){for(;*s&&*s>47&*s<58|*s>96&*s<123;++s);return!*s;}

Name: Anonymous 2009-05-25 16:37

>>81
Nice. But are you sure that &*s won't just return s?

Name: Anonymous 2009-05-25 16:47

>>84
Yes, there would be a parsing error otherwise (a value followed by another value without an operator in between).

Name: Anonymous 2009-05-25 16:52

Finally managed to move that incement to the condition.

is_inset(char*s){for(;*s>47&*s<58|*s>96&*s<123&&*s++;);return!*s;}

Name: Anonymous 2009-05-25 17:06

*s<123&&*s++
Remember that && short-circuits.

Name: Anonymous 2009-05-25 17:07

>>87
Goddamn that &&, always foiling my plans!!

Name: Anonymous 2009-05-25 22:30

>>88
Who said C optimization is easy?

Name: Anonymous 2009-05-26 0:05

>>86,88
comma operator.

Name: Anonymous 2009-05-26 3:39

>>90
Yeah, maybe I don't need the condition since the zero check would fall outside the ranges anyway.

is_inset(char*s){for(;*s>47&*s<58|*s>96&*s<123;++s);return!*s;}

Name: Anonymous 2009-05-26 4:12

sub is_inset{$_[0]!~/[^\da-z]/}

Name: ​​​​​​​​​​ 2010-10-23 3:29

Name: Anonymous 2010-12-09 14:41


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List