Search code examples
objective-ciosnscharacterset

Removing Character issue from NSString in iPhone


I have a string with value "€100,000,000". I want to remove the '€' and ',' at the same time. I am try to use [NSCharacterSet symbolSet] but this method only removes the '€' without removing the ','.


Solution

  • You can try:

    -(NSString*)cleanString:(NSString*)str
        NSString *string = [NSString stringWithString:str];
        NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"€,"];
        string = [string stringByTrimmingCharactersInSet:charSet];
        return string;
    }