本文介绍了从由特殊字符分隔的NSString中提取2个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像你好 - 这就是我的NSString。
我想搜索 - 并将 - 之前和之后的文本放在两个单独的字符串中。
i have an NSString like "Hello - this is me".I want to search for the "-" and put the text before and after the "-" in two separate strings.
任何人都知道怎么做最好的方式?
Anyone knows how to do that the best way?
迎接Max
推荐答案
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.
这篇关于从由特殊字符分隔的NSString中提取2个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!