• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: evalhate without parsing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: evalhate without parsing?


  • Subject: Re: evalhate without parsing?
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 02 May 2013 16:03:45 -0500

Hey Bob,

I'm not sure I understand

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.

If I know that string A is the old version and string B is the version I've just reached out to the net to compare against it then if they're not equal I know I have a new version.

but just comparing works.
Intuitively it would seem to me that the buried numbers wouldn't compare properly.

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

"a1b" = "a2b"
--> 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:

http://apod.nasa.gov/apod/astropix.html

http://apod.nasa.gov/apod/ap130501.html


-------------------------------------------------------------------------------------------

set _url to "http://apod.nasa.gov/apod/ap130501.html"
# set _url to "http://apod.nasa.gov/apod/astropix.html"

try
find text "http://apod.nasa.gov/apod/ap\\d{6}\\.html" in _url with regexp
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
find text "http://apod.nasa.gov/apod/ap\\d{6}\\.html" in _url with regexp
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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: evalhate without parsing?
      • From: Robert Poland <email@hidden>
References: 
 >evalhate without parsing? (From: Robert Poland <email@hidden>)
 >Re: evalhate without parsing? (From: Christopher Stone <email@hidden>)

  • Prev by Date: As and Excel
  • Next by Date: Re: As and Excel
  • Previous by thread: Re: evalhate without parsing?
  • Next by thread: Re: evalhate without parsing?
  • Index(es):
    • Date
    • Thread