Created
November 6, 2013 10:18
-
-
Save thomaswitt/7333822 to your computer and use it in GitHub Desktop.
Apple Script String Helpers
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 replace(sourcetext, search, replacement) | |
set oldDelim to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to the search | |
set the textItemList to every text item of the sourcetext | |
set AppleScript's text item delimiters to the replacement | |
set the output to the textItemList as string | |
set AppleScript's text item delimiters to oldDelim | |
return output | |
end replace | |
on strip_spaces(aLine) | |
--strip lead spaces | |
set ods to AppleScript's text item delimiters | |
repeat until first character of aLine is not " " | |
set AppleScript's text item delimiters to {""} | |
set aLine to (characters 2 thru -1 of aLine as string) | |
set AppleScript's text item delimiters to ods | |
end repeat | |
--strip tail spaces | |
set ods to AppleScript's text item delimiters | |
repeat until last character of aLine is not " " | |
log aLine | |
set AppleScript's text item delimiters to {""} | |
set aLine to (characters 1 thru -2 of aLine as string) | |
set AppleScript's text item delimiters to ods | |
end repeat | |
return aLine | |
end strip_spaces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment