我有一个 NSString,比如“你好 - 这是我”。 我想搜索“-”并将“-”前后的文本放在两个单独的字符串中。
有人知道怎么做最好吗?
问候麦克斯
最佳答案
NSArray *subStrings = [myString componentsSeparatedByString:@"-"]; //or rather @" - "
NSString *firstString = [subStrings objectAtIndex:0];
NSString *lastString = [subStrings objectAtIndex:1];
//Add some array range checking to it and you're done.
关于objective-c - 从由特殊字符分隔的 NSString 中提取 2 个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5614681/