IonicWind Software

Creative Basic => General Questions => Topic started by: aurelCB on September 22, 2009, 12:33:37 PM

Title: Insensitive strings
Post by: aurelCB on September 22, 2009, 12:33:37 PM
Hi people... :)
How make string with case insensitive?
Put another way - how to compare the two strings that have the same meaning.
For example if we have string "byte" and string "BYTE" , so how make program which can
recognize string writen as "bYte" or "Byte" or "byTE" ?
Is there any example how do that?

thanks advance...
Aurel
Title: Re: Insensitive strings
Post by: aurelCB on September 22, 2009, 01:27:02 PM
Oh my  ::) I must reply to myself.
I completly forget one simpliest solution( like usual...)
small example:
'MAIN SKELETON
DEF w1:window
def text,Str,keyword:string

Window w1,0,0,400,300,@minbox,0,"Strings",main
Setwindowcolor w1,rgb(200,200,200)
'-------------------------------------------------------
Str="nEw"
'so i just trnsform new string to lower case ...
keyword=Lcase$(Str)

IF keyword="new"
move w1,10,10:Print w1,keyword
ELSE
move w1,10,50:Print w1,"Not match..."
ENDIF


'----------------------------------
run=1
waituntil run=0
closewindow w1
end
'----------------------------------
Sub main
select @class
case @idclosewindow
run=0
case @idcreate
centerwindow w1
endselect
Return

Title: Re: Insensitive strings
Post by: Ionic Wind Support Team on September 22, 2009, 02:45:03 PM
That will work, but you can also use the lstrcmpi API function.

http://msdn.microsoft.com/en-us/library/ms647489(VS.85).aspx

The declare for Creative would be:

declare "kernel32",lstrcmpi(st1:string,str2:string),int

small example:


openconsole
declare "kernel32",lstrcmpi(st1:string,str2:string),int

if lstrcmpi("new","NeW") = 0
print "Matches"
endif


This would be the fastest solution.

Paul.
Title: Re: Insensitive strings
Post by: aurelCB on September 22, 2009, 03:04:53 PM
Great... :)
Thank you Paul!