Remove Special Characters in NSString

后端 未结 5 1933
野性不改
野性不改 2020-12-08 11:23

i am convert paragraph into words it contains many special characters like

\"  , \"  . `

how to remove this characters in nsstring and get

5条回答
  •  遥遥无期
    2020-12-08 12:26

    Per comment of @Rostyslav Druzhchenko from on the selected answer of @MadhuP:

    NSString *unfilteredString = @"!@#$%^&*()_+|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    NSCharacterSet *notAllowedChars = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
    NSString *escapedString = [[unfilteredString componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
    NSLog (@"Result: %@", escapedString);
    

    This is the answer that will use alphanumericCharacterSet to handle multiple countries character set.

提交回复
热议问题