• 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: Recursive Character Replacing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursive Character Replacing


  • Subject: Re: Recursive Character Replacing
  • From: "Ethan Rips" <email@hidden>
  • Date: Thu, 04 Sep 2003 16:51:04 -0400
  • Priority: normal

On Thu, 04 Sep 2003 julifos <email@hidden> wrote:

> Hi, James...
>
> You can make your code look shorter, but I don't think you can speed it up
> so much, unless you understand "much" as 5 milliseconds in a run ;-)
> Eg, you would win some speed using this routine:
>
> ########################################
> set searchStuff to {return, "", "", "", "", "", "<00AD>", "<FFFD>",
> "<E06E>", "<E06C>"}
> set replaceStuff to {CRLF, "\"", "\"", "'", "'", "-", "", "", "", "*"}
>
> tell (a reference to AppleScript's text item delimiters)
> repeat with i from 1 to searchStuff's length
> set contents to searchStuff's item i
> set myArticleString to myArticleString's text items
> set contents to replaceStuff's item i
> set myArticleString to myArticleString as string
> end repeat
> set contents to {""}
> end tell
> ########################################
>
> But not lots of speed...

I wrote a search & replace script a while ago (excerpted below) thinking I'd
gain some efficiency from the use of value pairs passed to a handler via a
loop. (The full script contains zillions of search criteria.) I gather from
your comments above that (aside from the learning experience) I was wasting
my time. Am I reading your comments incorrectly? Is there a more efficient
way to approach this? (I'm pretty green as an applescripter & don't know
anything about benchmarks and all that.)

--set search criteria as properties
property quotes : "\""
property squiggles : "V+"
property dateSquiggles : "(\\d+\\/\\d+\\/\\d+)V+"
property returnSpace : "\\r +"
property VALUE_QUSIP : "(#VALUE!(\\tADD)*)+"
property returnRun : "\\r\\r+"
property spaceRun : " +"
property twoDotRun : "\\.\\.+"
--Etc.

--set replacement values for property list
set propList to {{quotes, r_delete}, {squiggles, r_delete}, {dateSquiggles,
r_pattern1}, {returnSpace, "\\r\\t"}} --etc.

--set counter to loop thru propList
set i to item 1 of propList

repeat with i from 1 to count of propList
set a to item 1 of (item i of propList)
set b to item 2 of (item i of propList)
cleanFinancials(a, b)
end repeat

beep

on cleanFinancials(x, y)

--pass each value pair to function
set oldChars to x
set newChars to y
set srchRslt to {}

tell window 1 of application "BBEdit"

--set grep & literal search modes
set GrepS_options to {search mode:grep, starting at top:true, wrap
around:false, reverse:false, case sensitive:true, match words:true, extend
selection:false}
select insertion point before character 1

--test for presence of search item first; if present, replace it
set srchRslt to (find x options GrepS_options with selecting match)
if found of srchRslt then
tell application "BBEdit"
replace x using y searching in text 1 of text window 1
options GrepS_options
end tell
end if

end tell

end cleanFinancials

Thanks.

Ethan
DISCLAIMER:
The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.(A)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Recursive Character Replacing
  • Next by Date: Re: Script to use as part of rule in Mail
  • Previous by thread: Re: Recursive Character Replacing
  • Next by thread: Re: Recursive Character Replacing
  • Index(es):
    • Date
    • Thread