Re: Text Item Delimiter error
Re: Text Item Delimiter error
- Subject: Re: Text Item Delimiter error
- From: JollyRoger <email@hidden>
- Date: Sun, 18 Mar 2001 13:24:09 -0600
on 3/18/2001 12:09 AM, email@hidden at email@hidden wrote:
>
I'm writing a search/replace handler and don't understand the results I'm
>
getting.
(snip)
Why re-invent the wheel, though? Here's a perfectly good search & replace
handler I've been using for years:
on MungerString(searchStr, replaceStr, sourceStr)
-- replace <searchStr> with <replaceStr> in <sourceStr>
try
set searchStr to (searchStr as text)
set replaceStr to (replaceStr as text)
set sourceStr to (sourceStr as text)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchStr)
set theList to (every text item of sourceStr)
set AppleScript's text item delimiters to (replaceStr)
set theString to theList as string
set AppleScript's text item delimiters to oldDelims
return theString
on error errmsg
display dialog "MungerString() failed: " & errmsg
end try
end MungerString
Enjoy.
JR