Checking legality of a string
Eric Chatonet
eric.chatonet at sosmartsoftware.com
Wed Jan 25 11:06:04 EST 2006
Hi Graham,
If your string is not 3000 chars long, you could just test the ASCII
code of each char:
function RightStr pStr
local tChar,tCharToNum
-----
repeat for each char tChar in pStr
put charToNum(tChar) into tCharToNum
if not (tCharToNum = 95 \
or (tCharToNum >= 48 and tCharToNum <= 57) \
or (tCharToNum >= 65 and tCharToNum <= 90) \
or (tCharToNum >= 97 and tCharToNum <= 122)) then return false
end repeat
return true
end RightStr
Then
if not RightStr(<string>) then <statements> -- not a right string
else <other statements>
I think that there should be also a solution using matchText :-)
If you are interested in ASCCI code, look at charToNum and numToChar
functions.
On the other hand, ASCII Picker, an utility you will find on my
website might help you.
Le 25 janv. 06 à 16:25, graham samuel a écrit :
> What's the most economical way of checking that a string contains
> only certain characters? I'm just trying to check if a string
> contains letters, digits and underscores, and nothing else. The
> ways I've thought of doing it seem clunky. Basically I want to script
>
> if myString contains only <list of legal characters> then...
>
> Just can't see the slick way of doing it. Maybe I should go outside
> and check for mole damage instead...
Best Regards from Paris,
Eric Chatonet
------------------------------------------------------------------------
----------------------
http://www.sosmartsoftware.com/ eric.chatonet at sosmartsoftware.com/
More information about the use-livecode
mailing list