Skip to content

Instantly share code, notes, and snippets.

@xiangyuan
Created September 30, 2012 09:14
Show Gist options
  • Select an option

  • Save xiangyuan/3806303 to your computer and use it in GitHub Desktop.

Select an option

Save xiangyuan/3806303 to your computer and use it in GitHub Desktop.
object 去掉尾部符号
NSString * str = @"今天你还,好吗@?¥#¥";
// NSString *nStr = @"~`!@#$%^&*;:\"',.?";
NSMutableCharacterSet *set = [[NSMutableCharacterSet alloc] init];
[set formUnionWithCharacterSet:[NSCharacterSet lowercaseLetterCharacterSet]];//小写字母
NSLog(@"1 %@",[str stringByTrimmingCharactersInSet:set]);
[set formUnionWithCharacterSet:[NSCharacterSet uppercaseLetterCharacterSet]];//大写字母
NSLog(@"2 %@",[str stringByTrimmingCharactersInSet:set]);
[set formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];//符号
NSLog(@"3 %@",[str stringByTrimmingCharactersInSet:set]);
[set formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]];//标点
NSLog(@"4 %@",[str stringByTrimmingCharactersInSet:set]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment