Jump to content

How to make string comparison case-sensitive


Recommended Posts

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...