Re: Faster way to replace text in AppleWorks?
Re: Faster way to replace text in AppleWorks?
- Subject: Re: Faster way to replace text in AppleWorks?
- From: Jay Young <email@hidden>
- Date: Sun, 29 Sep 2002 15:51:02 -0500
Hi Dale,
I would recommend using the AppleScript Text Item Delimiters. If your
document isn't too big, you could store all the text in a variable and
then fix it with the Text Item Delimiters and then put it back in
AppleWorks. I tested this code in OS 10.2.1 with AS 1.9 and it seemed
to work okay.
Please take notice of what Michelle Steiner has asked. If you have
commas in any numbers, or even periods in email addresses, the Script
will put a space after these characters too.
In the end, this code should change a period, comma, and question mark
to a period-space, comma-space, and question mark-space. It will then
look for any 2 spaces next to each other and change them to 1 space in
a repeat loop until the document only contains 1 space in every space
location. I don't know if this is really what you're looking for, but
hopefully it will at least give you some ideas for a solution.
--------------------------------------------
tell application "AppleWorks 6"
activate
set AWTxt to document 1's text
set document 1's text to my AddSpace(AWTxt)
end tell
on AddSpace(AWTxt)
repeat with x in {".", ",", "?"}
set AppleScript's text item delimiters to x
set GetOrig to AWTxt's text items
set AppleScript's text item delimiters to (x & " ")
set AWTxt to GetOrig as string
set AppleScript's text item delimiters to ""
end repeat
repeat
if AWTxt contains " " then
set AppleScript's text item delimiters to " "
set GetOrig to AWTxt's text items
set AppleScript's text item delimiters to " "
set AWTxt to GetOrig as string
set AppleScript's text item delimiters to ""
else
exit repeat
end if
end repeat
return AWTxt
end AddSpace
--------------------------------------------
Hope this helps!
Jay
On Sunday, September 29, 2002, at 06:40 AM, Dale Gillard wrote:
>
Hi all
>
>
I have written a script that loops thru an AppleWorks document looking
>
for specific characters and replacing them eg ensuring a period/full
>
stop has a single space after it. As you can imagine, it takes quite a
>
while to do this even in a document of only a few hundred words.
>
>
Does anyone have any advice on how I could speed this up this process?
>
eg a 'you beaut' algorithm that's really fast at doing this rather
>
than my 'naive' algorithm.
>
>
Here's a snippet of the script so you can get an idea of what I'm
>
doing:
>
-----------------------------------------------------------------------
>
--
>
set space to " "
>
set CharCount to count of characters of front document
>
-- Start backwards to avoid loop variable being changed when a char is
>
added or removed.
>
repeat with aCharacter from CharCount to 1 by -1
>
-- If a comma or period is found
>
if character aCharacter of front document is comma or character
>
aCharacter of front document is period then
>
-- If 1 space does not follow it, add a space.
>
if character (aCharacter + 1) of front document is not space
>
then
>
make new character at character aCharacter of front document
>
with data space
>
end if
>
end if
>
end repeat
>
-----------------------------------------------------------------------
>
--
>
>
Many thanks
>
Dale Gillard
>
_______________________________________________
>
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.