Sign in to follow this  
Followers 0
Guillermo

comparing extended characters

7 posts in this topic

#1 ·  Posted (edited)

... obviously, I meant o = O but ó <> Ó ... :o

$a = "si"
$b = "SI"

If $a = $b Then
    MsgBox(0, $a & " / " & $b, "They're identical")
Else
    MsgBox(0, $a & " / " & $b, "They're different")
    
EndIf

$a = "sí"
$b = "SÍ"

If $a = $b Then
    MsgBox(0, $a & " / " & $b, "They're identical")
Else
        MsgBox(0, $a & " / " & $b, "They're different")
EndIf

I can't understand this. If AutoIT supports ANSI, why are special characters different depending on whether they're in lower or upper case?

My script deals with text and has to compare strings constantly, so this is a big issue for me. If I could understand how AutoIT "reads" these characters then I could figure out a solution.

Edited by Guillermo

Share this post


Link to post
Share on other sites



From the help section Operators

= Tests if two values are equal (case insensitive if used with strings). e.g. If $var= 5 Then (true if $var equals 5)

== Tests if two values are equal (case sensitive if used with strings)


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

If you check the helpfile regarding operators you will see that both = and == can be used for testing strings - but the results may be different.

= Tests if two values are equal (case insensitive if used with strings). == Tests if two values are equal (case sensitive if used with strings)

Share this post


Link to post
Share on other sites

I didn't make my point...

I've read the help file and I know the difference between "=" and "==". However, AutoIT behaves differently when testing extended characters.

melon = MELON (true)

melon == MELON (false)

but

melón = MELÓN (false)

melón == MELÓN (false)

If you try out the code I pasted in my first post you'll understand what I mean.

My question is why.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The simplest solution would be to use following:

$a = "si"
$b = "SI"

If $a = $b Then
    MsgBox(0, $a & " / " & $b, "They're identical")
Else
    MsgBox(0, $a & " / " & $b, "They're different")
    
EndIf

$a = "sí"
$b = "SÍ"
$c = StringUpper($a)
If $b = $c Then
    MsgBox(0, $a & " / " & $b, "They're identical")
Else
    MsgBox(0, $a & " / " & $b, "They're different")
EndIf

It's always the best to convert both arguments to the same "level" (Uppercase) before comparing. Then you are more flexible.

btw: I do not really know why it's different on special characters, but I mostly convert two strings before I compare them. That's why I never recognized such a problem :o

UTA

Edited by UTA

Share this post


Link to post
Share on other sites

Yeah, that's the funny part. After converting the strings to the same level everything works fine...

Wouldn't that be a bug?

Share this post


Link to post
Share on other sites

I'm not quite sure if that is a bug. I'm too lazy to test it in another programming language. I suppose that it is a "feature" :o which is based on the special characters. But as I said: I'm not sure...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0