Removing parentheses from the string in iOS

后端 未结 4 1940
迷失自我
迷失自我 2020-12-11 11:03

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:

相关标签:
4条回答
  • 2020-12-11 11:34

    Simply do this like below:

    NSString *finalStr = [initialStr stringByReplacingOccurenceOfString:@"(" withString:@""];
    finalStr = [finalStr stringByReplacingOccurenceOfString:@")" withString:@""];
    

    This will remove all the parentheses from the string:I found this answer on this developer's blog

    0 讨论(0)
  • 2020-12-11 11:34

    Swift 4.2 use replacingOccurrences

    For eg. to get Pizza from (Pizza)

    let foodWithParentheses = "(Pizza)"
    
    let pizzaWithoutParen = foodWithParentheses.replacingOccurrences(of: "(", with: "").replacingOccurrences(of: ")", with: "")
    
    print(pizzaWithoutParen)
    // output: Pizza
    
    0 讨论(0)
  • 2020-12-11 11:37

    The following code is working

    NSString *str=[[NSBundle mainBundle] objectForInfoDictionaryKey:@"string"];
    NSLog(@"%@",[[str stringByReplacingOccurrencesOfString:@")" withString:@""] stringByReplacingOccurrencesOfString:@"(" withString:@""]);
    
    0 讨论(0)
  • 2020-12-11 11:50

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

    0 讨论(0)
提交回复
热议问题