Sign in to follow this  
Followers 0
leuce

How to make string comparison case-sensitive

5 posts in this topic

G'day everyone

I'm using a script to compare a line of text in some program with a line of text in a text file. If the two lines of text aren't the same, then the script replaces the text in that program with the line from the text file.

Unfortunately it now appears that AutoIt doesn't do the comparison case-sensitively. It regards "FOO" as being equal to "foo" or "Foo", which is very bad for my purpose.

Here is the script:

Global $alldone
Global $changeddone
Global $filereadline

#include <File.au3>

#cs

A more advanced version of the script that compares what is currently in the segment with what is to be pasted, and if it is the same, then it doesn't paste (thereby not affecting the segment status).

#ce

HotKeySet ("{ESC}", "TheEnd")

While 1

$fileopen = FileOpen ("idiotica.txt", 128)
$filecountlines = _FileCountLines ("idiotica.txt")

MsgBox (0, "Click in Idiom!", "Click with your mouse in the first line in Idiom... you have 5 seconds!", 5)

Sleep ("5000") ; so actually you have 10 seconds...

WinWaitActive ("Idiom WorldServer", "")

$alldone = 0
$changeddone = 0

For $i = 1 to $filecountlines

WinWaitActive ("Idiom WorldServer", "")

$filereadline = FileReadLine ("idiotica.txt", $i)

Send ("^a")
Sleep ("100")
Send ("^c")
Sleep ("100")
$existingtext = ClipGet()
Sleep ("100")

If $existingtext = $filereadline Then
Send ("{DOWN}")
ElseIf $existingtext <> $filereadline Then
ClipPut ($filereadline)
Sleep ("100")
Send ("^a")
Sleep ("100")
Send ("^v")
Sleep ("100")
Send ("{DOWN}")
Sleep ("100")
$changeddone = $changeddone + 1
Else
MsgBox (0, "Comparison failed", "Comparison failed", 0)
Exit
EndIf

$alldone = $alldone + 1

Next

MsgBox (0, "Done!", "Did " & $alldone & " segments, of which " & $changeddone & " changed.", 10)
Exit

WEnd

Func TheEnd()
MsgBox (0, "Done!", "Did " & $alldone & " segments, of which " & $changeddone & " changed.", 10)
Exit
EndFunc

How can I ensure that the comparison is case-sensitive?

Thanks

Samuel

Share this post


Link to post
Share on other sites



Try this:

If "Foo" = "foo" Then
    msgBox(0,"","equal")
Else
    msgBox(0,"","not equal")
Endif

If "Foo" == "foo" Then
    msgBox(0,"","equal")
Else
    msgBox(0,"","not equal")
Endif

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Try this:

If "Foo" = "foo" Then
    msgBox(0,"","equal")
Else
    msgBox(0,"","not equal")
Endif

If "Foo" == "foo" Then
    msgBox(0,"","equal")
Else
    msgBox(0,"","not equal")
Endif

Thanks to both repliers -- the combination of the two replies gave me my answer.

Thanks

Samuel

Share this post


Link to post
Share on other sites

Or you could use StringCompare with flag 1.

William

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