NSString去除两边空格字符,like trim()
2011-07-16 18:54
281 查看
NSString *cleanString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
还有就是去除多于的空格,如下:
NSString *theString = @" Hello this is a long string! ";
NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];
NSArray *parts = [theString componentsSeparatedByCharactersInSet:whitespaces];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
theString = [filteredArray componentsJoinedByString:@" "];
相关文章推荐
- NSString去除两边空格字符,like trim()
- NSString去除两边空格字符,like trim()[转]
- NSString去除空格字符-包括两边字符trim()
- NSString去除空格字符-包括两边字符trim()
- javascript 去除字符两边的空格函数(仿asp的trim)
- Excel去除字符中的空格(trim)
- Java去除字符中的空格(trim)
- c++ string 字符无法准确去除两边空格!
- JS中去除字符串两边的空格(trim(str))
- JavaScript去除字符串两边空格 == trim
- JavaScript去除字符串两边空格trim
- 用 Trim 函数去除字符串两边空白字符 和 用索引访问字符串
- Javascript中去除两边的空格和JS中判断字符串中是否包含某字符
- JavaScript去除字符串两边空格trim
- Excel去除字符中的空格(trim)
- c总结5 --- 去除两边空格(空白字符)(指针学习4)
- Java去除字符中的空格(trim)
- JavaScript去除字符串两边空格trim
- iOS NSString去除其他字符(空格回车符)
- ltrim、rtrim与trim 去除空格或者别的字符