• 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: looking to correct Smiles measuretext command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: looking to correct Smiles measuretext command


  • Subject: Re: looking to correct Smiles measuretext command
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 26 Jun 2011 01:35:18 -0500

Hey Bob,

set foundString to fnd("[\s]+", str, true, true, true) -->error

Well.  This suffers from the usual escape issue in Applescript:

 set x to "\" --> error

 set x to "\\"
 log x

--> (*\*)

Although the result you'll see is "\\", this is simply escaping the escape character.  The actual result as you'll see in the Console in Smile is "\" without the quotes.

set str to "Your Broadband2Go Account Number and Programming Instructions"
set foundString to length of fnd("[\\s]", str, false, true, true) --> 6

Note that '\s' is whitespace and comprises ' ' (space), tabs, returns, and linefeeds.

set str to "Your Broadband2Go Account Number and Programming Instructions.
Topic: Regular Expressions In Applescript"
set foundString to length of fnd("[\\s]", str, false, true, true) --> 12

This one is easy to account for:

set str to "Your Broadband2Go Account Number and Programming Instructions"
set foundString to fnd("[NA ]+", str, true, true, true) --> 6 - should be 18
set stringCount to length of foundString

Remember that the handler call has case-sensitive turned [ON].

Also remember that '+' means one or more.  So if you have one or more of the designated characters in sequence they'll only count as 1 item.  When we remove the '+' sign things work more as you were expecting.  We also need to account for letters of both cases.

So to get your 18 characters we need to rewrite it thus:

 set foundString to fnd("[nNaA ]", str, true, true, true) --> 18

OR

You could turn off case-sensitive:

 set foundString to fnd("[na ]", str, false, true, true) --> 18

Regular Expressions are finicky and can be confusing - even when you've been using then a long time as I have.  :)

Let me know if you need any more help.

Oh, if you don't have TextWrangler (freeware) please grab a copy, so you'll have a place to test regular expressions.

--
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: looking to correct Smiles measuretext command
      • From: Robert Poland <email@hidden>
References: 
 >looking to correct Smiles measuretext command (From: Robert Poland <email@hidden>)
 >Re: looking to correct Smiles measuretext command (From: Christopher Stone <email@hidden>)
 >Re: looking to correct Smiles measuretext command (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: looking to correct Smiles measuretext command
  • Next by Date: Re: width of column id name column
  • Previous by thread: Re: looking to correct Smiles measuretext command
  • Next by thread: Re: looking to correct Smiles measuretext command
  • Index(es):
    • Date
    • Thread