Created
May 6, 2015 20:08
-
-
Save madvas/8e1d8c680a35a2d45b09 to your computer and use it in GitHub Desktop.
Applescript escape XML special chars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on escapeString(toEscape) | |
set res to replaceChars(toEscape, "\"", """) | |
set res to replaceChars(res, "'", "'") | |
set res to replaceChars(res, "&", "&") | |
set res to replaceChars(res, ">", ">") | |
set res to replaceChars(res, "<", "<") | |
return res | |
end escapeString | |
on replaceChars(this_text, search_string, replacement_string) | |
set AppleScript's text item delimiters to the search_string | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the replacement_string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replaceChars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment