Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

The answer:

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

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

My code looks like this:

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

Need some guidance on this...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
726 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...