PDA

View Full Version : Compare two strings including case?



NanoGator
07-21-2004, 02:32 PM
I just have a quick question.



x1="Test";
x2="TEST";
if (x1 == x2)
{
info("Match!");
}




Why is it when I run this, I get the 'Match" message? Since those variables are of different case, why are they considered the same? Is there something I can do to make it case sensitive?

#lwrs_web
07-21-2004, 02:53 PM
(x1 - x2) == ""

(x1.hash() == x2.hash())

NanoGator
07-21-2004, 02:58 PM
I was unable to find hash in the reference or user manual for lscript, so I hope you don't mind this question.

Is .hash() akin to looking at the character codes?

#lwrs_web
07-21-2004, 06:53 PM
patch: v1.4.5 released: 04.20.99
...
A new integral object method has been added called hash(). This
method, useful only with character strings, will return an integer
value that represents a calculated hash value for that string. The
array type also responds to this method, and will calculate a hash
value for all string elements in the array.
...

NanoGator
07-21-2004, 07:27 PM
Originally posted by #lwrs_web
patch: v1.4.5 released: 04.20.99
...
A new integral object method has been added called hash(). This
method, useful only with character strings, will return an integer
value that represents a calculated hash value for that string. The
array type also responds to this method, and will calculate a hash
value for all string elements in the array.
...

Cheers, thank you. :)

I think that answerr'll help me a lot. I do have one more qusetion, but it's not critical to my scripting here. Couldn't this approach in rare circumstances cause a false match? I mean, if it adds the values together, couldn't you have two strings (not in the upper/lower case consideration...) that are listed as a match end up being different? Like, wouldn't "Ii" == "iI"?

Just a point of curiosity.

#lwrs_web
07-21-2004, 07:42 PM
yes forget this hash... I checked the return values and iI is indeed the same as Ii

I thought it's something like MD5
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html

.:Xk-Liber:.
09-16-2004, 04:29 AM
Hi guys, I've the same pb.
but.. even if there is the "new" hash() function added in the Release Notes 1.4.5 I've tried it but.... result : "Unresolved function reference: hash()" :eek:
(in the Modeler and in the Layout).
Why ..? :confused:
I'm workin' on LW8.01


But this trick :
var1 = "MotionMixer";
var2 = "MotionMIxer";

if((var1 - var2) == "")
info("Uh Oh ...! Looks like the same.");
else
info("Those strings are different.");