Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with replacing special characters

Tags:

xcode

iphone

ios5

Im having a issue with removing special characters from the string .I used the following code.But dint work.Please suggest me better logic

- (NSString *)trimmedReciString:(NSString *)stringName 
{
    NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"-/:;()$&@\".,?!\'[]{}#%^*+=_|~<>€£¥•."];
    for (int i = 0; i < [stringName length]; i++) {
        unichar c = [stringName characterAtIndex:i];
        if ([myCharSet characterIsMember:c]) {
            NSLog(@"%@",[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]]);
            stringName =  [stringName stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]] withString:@""];  

        }
    }
    return stringName;
}
like image 943
Priyan Haridas Avatar asked Feb 02 '26 08:02

Priyan Haridas


1 Answers

NSString *s = @"$$$hgh$g%k&fg$$tw/-tg";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"-/:;()$&@\".,?!\'[]{}#%^*+=_|~<>€£¥•."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"String is: %@", s);
like image 103
Eager Beaver Avatar answered Feb 03 '26 21:02

Eager Beaver



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!