IOS简单的字串替换方法stringByTrimmingCharactersInSet
2012-07-26 19:30
351 查看
此方法只能过滤掉首尾,但是条件是集合
今天听人介绍了一个比较简单的过滤方法...不多说了,直接上代码
发现这个方法有一个很大的缺点..比如要去掉(ABC)的英文部分..必须要先去掉外面的括号....不然无法过滤...
空格亦是如此
如果有更好的过滤方法,欢迎留言讨论
今天听人介绍了一个比较简单的过滤方法...不多说了,直接上代码
NSString *str = @"一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入"; 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]); [set formUnionWithCharacterSet:[NSCharacterSet controlCharacterSet]];//控制符 NSLog(@"5 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet decimalDigitCharacterSet]];//小数 NSLog(@"6 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];//文字 NSLog(@"7 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet nonBaseCharacterSet]];//非基础 NSLog(@"8 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];//字母数字 NSLog(@"9 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet decomposableCharacterSet]];//可分解 NSLog(@"10 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet illegalCharacterSet]];//非法 NSLog(@"11 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet capitalizedLetterCharacterSet]];//大写 NSLog(@"12 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet newlineCharacterSet]];//换行符 NSLog(@"13 %@",[str stringByTrimmingCharactersInSet:set]); [set formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//空格换行 NSLog(@"14 %@",[str stringByTrimmingCharactersInSet:set]);
2012-07-26 19:11:01.863 yingkong1987[12876:fb03] 1 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 2 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 3 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.864 yingkong1987[12876:fb03] 4 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 5 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 6 一个 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 汉0932字#@!中..文//>?输~~~@#$#@%#^#^%&^*&(*)入 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 7 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 8 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:01.865 yingkong1987[12876:fb03] 9 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:01.866 yingkong1987[12876:fb03] 10 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 11 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 12 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 13 (ABC) #@!#^#G@#Dd21e12d!E@!212s012yhsn 2012-07-26 19:11:02.170 yingkong1987[12876:fb03] 14
发现这个方法有一个很大的缺点..比如要去掉(ABC)的英文部分..必须要先去掉外面的括号....不然无法过滤...
空格亦是如此
如果有更好的过滤方法,欢迎留言讨论
相关文章推荐
- IOS简单的字串替换方法stringByTrimmingCharactersInSet
- IOS简单的字串替换方法stringByTrimmingCharactersInSet 和空格的替换 ()
- iOS简单的字串替换方法stringByTrimmingCharactersInSet
- IOS简单的字串替换方法stringByTrimmingCharactersInSet
- IOS简单的字串替换方法stringByTrimmingCharactersInSet
- iOS: NSString的方法stringByTrimmingCharactersInSet:
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等
- iOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- IOS简单的字串替换方法stringByTri…
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet 应该用于账号登录等
- 字符串特殊字符特殊处理方法:stringByTrimmingCharactersInSet
- 【OC】去除首尾字符串的方法stringByTrimmingCharactersInSet