NSString字符转换

发表:2013-05-04 23:00:57

1 NSString *str = @"一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入";
 2     NSMutableCharacterSet *set = [[NSMutableCharacterSet alloc] init];
 3     [set formUnionWithCharacterSet:[NSCharacterSet lowercaseLetterCharacterSet]];//小写字母
 4     NSLog(@"1 %@",[str stringByTrimmingCharactersInSet:set]);
 5     [set formUnionWithCharacterSet:[NSCharacterSet uppercaseLetterCharacterSet]];//大写字母
 6     NSLog(@"2 %@",[str stringByTrimmingCharactersInSet:set]);
 7     [set formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];//符号
 8     NSLog(@"3 %@",[str stringByTrimmingCharactersInSet:set]);
 9     [set formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]];//标点
10     NSLog(@"4 %@",[str stringByTrimmingCharactersInSet:set]);
11     [set formUnionWithCharacterSet:[NSCharacterSet controlCharacterSet]];//控制符
12     NSLog(@"5 %@",[str stringByTrimmingCharactersInSet:set]);
13     [set formUnionWithCharacterSet:[NSCharacterSet decimalDigitCharacterSet]];//小数
14     NSLog(@"6 %@",[str stringByTrimmingCharactersInSet:set]);
15     [set formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];//文字
16     NSLog(@"7 %@",[str stringByTrimmingCharactersInSet:set]);
17     [set formUnionWithCharacterSet:[NSCharacterSet nonBaseCharacterSet]];//非基础
18     NSLog(@"8 %@",[str stringByTrimmingCharactersInSet:set]);
19     [set formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];//字母数字
20     NSLog(@"9 %@",[str stringByTrimmingCharactersInSet:set]);
21     [set formUnionWithCharacterSet:[NSCharacterSet decomposableCharacterSet]];//可分解
22     NSLog(@"10 %@",[str stringByTrimmingCharactersInSet:set]);
23     [set formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]];//非法
24     NSLog(@"11 %@",[str stringByTrimmingCharactersInSet:set]);
25     [set formUnionWithCharacterSet:[NSCharacterSet capitalizedLetterCharacterSet]];//大写
26     NSLog(@"12 %@",[str stringByTrimmingCharactersInSet:set]);
27     [set formUnionWithCharacterSet:[NSCharacterSet newlineCharacterSet]];//换行符
28     NSLog(@"13 %@",[str stringByTrimmingCharactersInSet:set]);
29     [set formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//空格换行
30     NSLog(@"14 %@",[str stringByTrimmingCharactersInSet:set]);


相关文章