objective-c - 从由特殊字符分隔的 NSString 中提取 2 个字符串

标签 objective-c ios nsstring

我有一个 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/

相关文章:

iphone - NSArray 组件SeperatedByString Sigabrt

iphone - 当 View Controller 弹出时,MKMapView 使应用程序崩溃

ios - 单击按钮每周一次的本地通知

ios - 可以从托管 SwiftUI View 调用 UIKit UIViewController 中的闭包吗?

ios - 使用 Realm 查询返回唯一/不同的值

iphone - UITableView titleForSection 字体

iphone - 来自自定义 .XIB 文件的 UITableViewCell 不会创建导出

ios - 在iPAD上检测iPhone特定的应用程序“正在运行”

ios - 调整 NSMutableAttributedString 中字符的垂直高度

objective-c - 将 CSV 中带引号的字符串转换为不带引号的 NSMutableArray