Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Fri Sep 20, 2002 8:06 am Post subject: String evaluation - alphabetic/alphanumeric/numeric |
|
|
Hmmm, am I spamming this forum?
Well, at any rate, here is a tool for evaluating strings in alphabetic/alphanumeric/numeric mode:
The basic idea for this is Mac's. It has been enhanced to support extended chars in the normal Western European character set.
| Code: |
option decimalsep,"."
dialog CREATE,Find characters,-1,0,260,220
dialog ADD,EDIT,EvalString,5,5,250,,1st Enter string!
dialog ADD,RADIO,mode,35,5,140,,Select mode:,1. Alphabetic|2. Alphanumeric|3. Numeric,"1. Alphabetic",CLICK
dialog ADD,CHECK,case,120,5,200,,case-sensitive
dialog ADD,CHECK,extended,135,5,250,,"use extended character set (Western European)"
dialog ADD,BUTTON,Go,180,40,140,,Go!
dialog ADD,TEXT,Dread,205,180,140,,.. by Dr. Dread
dialog SHOW
%%mode = "alpha"
:Evloop
wait event
wait .2
goto @event()
:modeCLICK
%M = @substr(@dlgtext(mode),1,)
if @equal(%M,1)
%%mode = "alpha"
dialog enable,case
dialog enable,extended
end
if @equal(%M,2)
%%mode = "alphanum"
dialog disable,case
dialog enable,extended
end
if @equal(%M,3)
%%mode = "numeric"
dialog disable,case
dialog disable,extended
end
goto evloop
:GoBUTTON
%i = @dlgtext(EvalString)
if @null(%i)
warn Enter string to be evaluated!
end
if @null(@dlgtext(case))
%%casesense = "0"
else
%%casesense = "1"
end
if @null(@dlgtext(extended))
%%extended = "0"
else
%%extended = "1"
end
if @equal(%%mode,alpha)
if @equal(%%casesense,0)
if @equal(%%extended,1)
%%chars = "abcdefghijklmnopqrstuvwxyz íŸ€íµŸ"
gosub alpha
else
%%chars = "abcdefghijklmnopqrstuvwxyz"
gosub alpha
end
else
if @equal(%%extended,1)
%%LC = "abcdefghijklmnopqrstuvwxyz"
%%LCextended = " "
%%UCextended = " íŸ€íµŸ"
gosub alpha-sense
else
%%LC = "abcdefghijklmnopqrstuvwxyz"
%%LCextended = ""
%%UCextended = ""
gosub alpha-sense
end
end
end
if @equal(%%mode,alphanum)
if @equal(%%extended,1)
%%chars = "0123456789abcdefghijklmnopqrstuvwxyz íŸ€íµŸ"
gosub alphanum
else
%%chars = "0123456789abcdefghijklmnopqrstuvwxyz"
gosub alphanum
end
end
if @equal(%%mode,numeric)
gosub numeric
end
goto evloop
:CLOSE
exit
REM ######## SUBs ##########
:alpha
if %i
%x = 1
%a = ""
%u = ""
repeat
%%pos = @pos(@substr(%i,%x),%%chars)
%%char = @substr(%i,%x)
if @greater(%%pos,0)
%a = %a%%char
else
%u = %u%%char
end
%x = @succ(%x)
until @greater(%x,@len(%i))
info String: %i@tab()@cr()@cr()Alphabetic: %a@cr()@cr()Not alphabetic: %u
end
EXIT
:alpha-sense
if %i
%x = 1
%l = ""
%u = ""
%n = ""
repeat
%%pos = @pos(@substr(%i,%x),%%LC)
%%char = @substr(%i,%x)
if @greater(%%pos,0)
if @equal(%%char,@substr(%%LC,%%pos),EXACT)
%l = %l%%char
else
%u = %u%%char
end
else
%%extpos1 = @pos(%%char,%%LCextended)
%%extpos2 = @pos(%%char,%%UCextended)
if @greater(%%extpos1,0)@greater(%%extpos2,0)
if @greater(%%extpos2,0)
%u = %u%%char
else
%l = %l%%char
end
else
%n = %n%%char
end
end
%x = @succ(%x)
until @greater(%x, @len(%i))
info String: %i@tab()@cr()@cr()Upper case: %u@cr()@cr()Lower case: %l@cr()@cr()Not alphabetic: %n
end
EXIT
:alphanum
if %i
%x = 1
%a = ""
%u = ""
repeat
%%pos = @pos(@substr(%i,%x),%%chars)
%%char = @substr(%i,%x)
if @greater(%%pos,0)
%a = %a%%char
else
%u = %u%%char
end
%x = @succ(%x)
until @greater(%x,@len(%i))
info String: %i@tab()@cr()@cr()Alphanumeric: %a@cr()@cr()Not alphanumeric: %u
end
EXIT
:numeric
if %i
%x = 1
%u = ""
%n = ""
repeat
%%char = @substr(%i,%x)
if @numeric(%%char)
%n = %n%%char
else
%u = %u%%char
end
%x = @succ(%x)
until @greater(%x,@len(%i))
info String: %i@tab()@cr()@cr()Numeric: %n@cr()@cr()Not numeric: %u
end
EXIT
|
_________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|