I'm just doing a straight one-to-one string comparison.
But if it's false I'm extracting the build and version numbers from the second string.
Quite the opposite really. If the strings are different then a straight comparison will produce false. If the strings are the same it will produce true.
"abc" = "abc"
--> true
"abc" = "cba"
--> false
"a1b" = "a1b"
--> true
"a1b" = "b1a"
--> false
-------------------------------------------------------------------------------------------
You can also use the Satimage.osax's regular expressions to do a compare:
-------------------------------------------------------------------------------------------
set strA to "Smile 3.6.1 (build 710) full edition"
set strB to "Smile 3.7.0 (build 768) full edition"
# Escape regex operators:
set strB to change "([?.(){}])" into "\\\\\\1" in strB with regexp
# Add beginning and end of line anchors:
set strB to "^" & strB & "$"
try
find text strB in strA with regexp
set compare1 to true
on error
set compare1 to false
end try
set strC to "Smile 3.7.0 (build 768) full edition"
try
find text strB in strC with regexp
set compare2 to true
on error
set compare2 to false
end try
-------------------------------------------------------------------------------------------
But you wouldn't do this when you can just do 'String1' = 'String2'.
On the other hand you would do it if you wanted to match a specific regular _expression_.
So I might want to act differently if I'm on the main apod web page or a previous one:
-------------------------------------------------------------------------------------------
try
set _flag to true
on error
set _flag to false
end try
if _flag = true then
return "Do Something!"
else
return "Do Something Else!"
end if
-------------------------------------------------------------------------------------------
I can make that more terse and turn the try block into an if-then-else.
This works, because the Satimage.osax throws an error if the string is not found.
-------------------------------------------------------------------------------------------
tell application "Safari"
set _url to URL of front document
end tell
try
return "Do Something!"
on error
return "Do Something Else!"
end try
-------------------------------------------------------------------------------------------
I have a regex handler that specifically does a true/false evaluation:
-------------------------------------------------------------------------------------------
on fndBool(findStr, srcData, caseSensitive, allOccurrences, stringResult)
try
set findResult to find text findStr in srcData case sensitive caseSensitive ¬
all occurrences allOccurrences string result stringResult with regexp
return true
on error
return false
end try
end fndBool
set _data to "Now is the time for all good men to come to the aid of their country."
if fndBool("the time.*?good men", _data, false, false, false) = true then
# Do something
# OR
# Do something *with* the match:
matchResult of result
end if
-------------------------------------------------------------------------------------------
--
Best Regards,
Chris