Re: Recursive Character Replacing
Re: Recursive Character Replacing
- Subject: Re: Recursive Character Replacing
- From: julifos <email@hidden>
- Date: Thu, 04 Sep 2003 19:45:30 +0200
>
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.