This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
Y
YaNuSH
Post
by YaNuSH » Tue Aug 06, 2002 10:35 am
how do i check whether a certain string contains only capital letters and numbers?
how do i check whether the 4th character in a string is a number?
i heard u can do all these with regular expressions but unfortunately i have no idea how to use them
ppslim
Revered One
Posts: 3914 Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England
Post
by ppslim » Tue Aug 06, 2002 11:05 am
You can do it with regular expressions and Tcl (version dependant)
This should work however.
proc is_only_cap_and_num {t} {
regsub -all -- {[A-Z0-9]} $t "" t
if {$t == ""} { return 1 }
return 0
}
Will return 1 is it is only capc or numbers - no spaces, lower case or any other character allowed.
proc is_4th_char_a_num {t} {
regsub -aa -- {[0-9]} [string index $t 3] "" t
if {$t == ""} { return 1 }
return 0
}
Will return 1 with the 4th character is a number.
Both can be done in Tcl, but can be long winded.
Y
YaNuSH
Post
by YaNuSH » Tue Aug 06, 2002 1:05 pm
ty very much. that worked. u really helped me alot.