我需要按特定单词将 NSString
拆分为数组。
我尝试使用[componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@""]]
但是分割是由单个字符执行的,我需要几个字符。
例子:
NSString @"Hello great world";
分割键==@“很棒”;
结果:
array[0] == @"Hello";
array[1] == @"world";
最佳答案
尝试
NSString *str = @"Hello great world";
//you can use the bellow line to remove space
//str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
// split key = @"great"
NSArray *arr = [str componentsSeparatedByString:@"great"];
关于ios - 按特定单词将 NSString 拆分为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33208899/