An AppleScript Replace Text Method

Submitted by:David Villa

Date added:13 December, 2011

Category:AppleScript

You can use to find and replace text in a variable. This script created by Bruce Phillips, one of the leading posters at MacScripter.

Tags: replace text

Code Snippet:

on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject

set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs

return subject
end replaceText

get replaceText("Windows", "the Mac OS", "I love Windows and I will always love Windows and I have always loved Windows.")
 
 

Comments