Search code examples
objective-cnsstringtrim

How to Trim special Characters in a String in Objective c


I want to trim the occurence of special characters in a string

String  has :    
prevs: Case Number                                                                    
____________________

In this i want to remove -------- this dash from this string .I have tried like this :

NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"-"];
    NSString *stringNew = [[previousString2 componentsSeparatedByCharactersInSet:trim] componentsJoinedByString:@""];

Thanks in Advance!


Solution

  • Try This:

    NSString *stringWithoutDash = [yourString stringByReplacingOccurrencesOfString:@"-" withString:@""];