Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove string between two characters

This my example string

String of words in (brackets) to be (removed)

I want to remove all the words inside brackets, along with the pair of brackets, after which the string will look like this:

String of words in to be

like image 906
Janub Avatar asked Sep 19 '26 22:09

Janub


2 Answers

Use reg expression to remove the string Like following ( this @"\\(.+?\\)" is the regexp for string between ( and ) )

NSMutableString *str = [@"String of words in (brackets) to be (removed)" mutableCopy];

NSRegularExpression *regex = [NSRegularExpression         
                              regularExpressionWithPattern:@"\\(.+?\\)"
                              options:NSRegularExpressionCaseInsensitive
                              error:NULL];

[regex replaceMatchesInString:str 
                      options:0 
                        range:NSMakeRange(0, [str length])  
                 withTemplate:@""];
like image 140
Omar Abdelhafith Avatar answered Sep 21 '26 14:09

Omar Abdelhafith


you can split string on space bases then after you take array index..and combined that string.

like image 23
v_1 Avatar answered Sep 21 '26 14:09

v_1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!