在iOS中从字符串中删除括号 [英] Removing parentheses from the string in iOS

查看:299
本文介绍了在iOS中从字符串中删除括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除iOS中字符串中的所有括号.看到了这个stackoverflow帖子:如何删除空格,方括号和来自nsarray

I am trying to remove all the parentheses in my string in iOS. Saw this stackoverflow post: how to remove spaces, brackets and " from nsarray

答案:

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

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

But this just removes one bracket which is ( from mystring. How to remove all of them?

我的代码如下:

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"( )"];
attributedLabel.text = [attributedLabel.text stringByTrimmingCharactersInSet:charsToTrim];
NSLog(@"%@",attributedLabel.text);

对此需要一些指导...

Need some guidance on this...

推荐答案

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

Try using
[[attributedLabel.text stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""];
instead.

这篇关于在iOS中从字符串中删除括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆