我在文本字段中有以下文字
Taj,Restraint,Renovation,Catch
如何从文本字段中单独获取Catch单词。
答案 0 :(得分:1)
试试这个
NSString *myString = @"Taj, Restraint, Renovation, Catch" ;
__block NSString *lastWord = nil;
[myString enumerateSubstringsInRange:NSMakeRange(0, myString.length) options:(NSStringEnumerationByWords | NSStringEnumerationReverse) usingBlock:^(NSString *substring, NSRange subrange, NSRange enclosingRange, BOOL *stop) {
lastWord = substring;
*stop = YES;
}];
答案 1 :(得分:1)
NSString *str = @"The Taj, Restraint, Renovation, Catch";
NSString *lastWord = [[str componentsSeparatedByString:@","] lastObject];