• 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: Jean-Baptiste LE STANG <email@hidden>
  • Date: Thu, 4 Sep 2003 20:25:49 +0200

It might be quicker using an osax, using Satimage.osax you can do the following :

repeat with x from 1 to count searchStuff
set myDosArticle to change (item x of searchStuff) into (item x of replaceStuff) in myDosArticle
end repeat

OMM : a text of 200 000 characters, all changes were made in 8.5 seconds (CPU : 400)

@+ JB

Le jeudi, 4 sep 2003, ` 19:45 Europe/Paris, julifos a icrit :

Hi guys,

little advice required. I have a long script, which basically
generates a
decent sized chunk of text (held in myArticleString variable) which gets
output to a file.

Before I output the string to a file, I need to do some basic character
replacement, which i currently do with the following:

set myDosArticle to my replace_chars(myArticleString, return, CRLF)
set myDosArticle to my replace_chars(myDosArticle, "", "\"")
set myDosArticle to my replace_chars(myDosArticle, "", "\"")
set myDosArticle to my replace_chars(myDosArticle, "", "'")
set myDosArticle to my replace_chars(myDosArticle, "", "'")
set myDosArticle to my replace_chars(myDosArticle, "", "-")
set myDosArticle to my replace_chars(myDosArticle, "<00AD>", "")
set myDosArticle to my replace_chars(myDosArticle, "<FFFD>", "")
set myDosArticle to my replace_chars(myDosArticle, "<E06E>", "")
set myDosArticle to my replace_chars(myDosArticle, "<E06C>", "*")

(among others!). The replace_chars subroutine is taken from the
applescript
essential subroutines on the applescript site.

My question - is there a more efficient way to do this
(programatically)? I
am a relatively new applescripter (this list has been great for
learning...), and any advice is appreciated!

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...

jj
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Recursive Character Replacing
      • From: Emmanuel <email@hidden>
References: 
 >Re: Recursive Character Replacing (From: julifos <email@hidden>)

  • Prev by Date: Microsoft Word 5.1 versus Word for Office X
  • 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