The NSString method componentsSeparatedByString:
will do basically the same thing as text items
in Applescript. You can call than, then access objects from the array to get the substrings. This example grabs all the text after the last occurrence of "Jarvis>" in the original string:
NSString* originalString; //comes from somewhere
NSArray* substrings = [originalString componentsSeparatedByString:@"Jarvis>"];
NSString* lastSubstring = [substrings lastObject];
However, if you just want to grab a substring off the front or the back of an existing string, take a look at rangeOfString:
, substringToIndex:
, and substringFromIndex:
. You would first use rangeOfString:
to find the string you want to separate by, then one of the substring methods to grab the actual text you want. This is somewhat more efficient that componentsSeparatedByString:
if you only want to access a single substring, rather than every single substring separated by your text delimiter. This example grabs all the text before the first occurrence of "[Jarvis]" in the original string:
NSRange jarvisRange = [originalString rangeOfString:@"[Jarvis]"];
NSString* substring = [originalString substringToIndex:jarvisRange.location];
You can also use rangeOfString:options:
passing in NSBackwardsSearch
to the options parameter if you want to search from the end of the string rather than the front.