There are a lot of handy string functions in most languages. You can find a list of equivalents for various Python string functions here. One commonly used string function is offset, which can find a string. If you are searching for the word “needle” in a string variable called “haystack” then doing this:
offset of "needle" in haystack
will return the start position of “needle” and if it doesn’t find needle at all, will return 0.
4 Comments
Text manipulation is definitely not one of AppleScript’s strong points, and its out-of-the-box support for it really sucks. However, if you’re working in Studio you can easily take advantage of Cocoa’s own NSString methods and third-party text processing frameworks such as RegexKit. For example, to uppercase an AppleScript string:
set myText to call method “uppercaseString” of myText
For non-Studio-based projects, your best bet would be to use a Unicode-aware scriptable text editor, e.g. TextWrangler, or scripting addition/scriptable faceless background application, e.g. TextCommands.
HTH
I will have to look into some more of thos NSString methods within Cocoa! Thanks for passing that info along!
Intersting, I can’t seem to get that call method command to compile in a test application.
“I can’t seem to get that call method command to compile in a test application.”
If cutting and pasting, beware WordPress’s curly quotes. AppleScript requires straight double quotes for string literals.