我正在尝试删除iOS中字符串中的所有括号。看到了这个stackoverflow帖子:how to remove spaces, brackets and " from nsarray

答案:

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"];
s = [s stringByTrimmingCharactersInSet:charsToTrim];

但这只是从mystring中删除了一个括号(如何删除所有括号?

我的代码如下所示:
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"( )"];
attributedLabel.text = [attributedLabel.text stringByTrimmingCharactersInSet:charsToTrim];
NSLog(@"%@",attributedLabel.text);

需要一些指导...

最佳答案

尝试使用[[attributedLabel.text stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""];代替。

10-08 05:33