Re: Case sensitive find/replace
Re: Case sensitive find/replace
- Subject: Re: Case sensitive find/replace
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 21 Jul 2006 14:03:59 -0700
>>>>There are two complications. The number of instances of the "find" text in
the box will change with each replacement, thus we need to keep track of
occurrences of the text with an adjustable index ...
Or, here's a variation that's a bit shorter and runs much faster.
Simply get a list of all the references to your text, reverse the list and replace from the back. Even if your replacement string is a different length than your search string it doesn't matter.
Try this:
-------Script starts here-------
set findText to "the"
set replaceText to "T H E"
tell application "QuarkXPress(tm) 4.11"
set i to 0 -- initialize the index
tell story 1 of current box
try
set foundLocations to object reference of every text whose it = findText
on error number -1728 -- no more occurrences found
return ""
end try
end tell
set foundLocations to the reverse of foundLocations
repeat with thisLocation in foundLocations
set theText to (contents of thisLocation) as text
considering case
if theText is findText then -- case matches, so replace text
set text of thisLocation to replaceText
set i to i - 1 -- decrement index
end if
end considering
end repeat
end tell
-----Script ends here-----
*(Yes, I'm still using Quark 4/OS 9, but this should work on 6/X)*
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden