objective-c - stringByReplacingOccurrencesOfString 循环?

标签 objective-c nsstring

NSString *qwer2 = [qwer1 stringByReplacingOccurrencesOfString:@"count '0','" withString:@""];

NSString *qwer4 = [qwer2 stringByReplacingOccurrencesOfString:@"count '1','" withString:@""];

NSString *qwer = [qwer4 stringByReplacingOccurrencesOfString:@"count '2','" withString:@""];

如何用任意数字替换字符串?

count '0' , count '1' , count '2'

count 'any numbers'

我已经尝试过循环:

for (int i =0; i<100; i++) 

NSString *qwer = [qwer4 stringByReplacingOccurrencesOfString:@"count 'i','"withString:@""];

最佳答案

NSString *replaced = [string stringByReplacingOccurrencesOfString:@"count '\\d+','"
                           withString:@""
                              options:NSRegularExpressionSearch
                                range:NSMakeRange(0, string.length)];

应该可以解决问题。 “\d+”是匹配一个或多个数字的正则表达式模式。

关于objective-c - stringByReplacingOccurrencesOfString 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933632/

相关文章:

ios - 为什么这个 NSMutableAttributedString addAttribute 只有在我使用 mutableCopy 时才有效

iOS 7,在后台检查更新

iphone - 从 UIPageViewController 中移除 View Controller

ios - 高内存使用循环通过 PHAsset 并调用 requestImageForAsset

objective-c - @interface 中带有## 的宏,是什么意思?

ios - TextView 字符串中子字符串的颜色

iphone - 如何获取NSString的十进制ascii码?

ios - UITableView 标题样式 - 字体颜色/背景/字体大小

nsstring 的 IOS 发布和分配消息差异

iphone - 描述方法中的断线不起作用