- (NSString *)filterBlankAndBlankLines:(NSString *)str
{
NSMutableString *Mstr = [NSMutableString string];
NSArray *arr = [str componentsSeparatedByString:@"\n"];
for (int i = 0; i < arr.count; i++) {
NSString *tempStr = (NSString *)arr[i];
[tempStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; //去除掉首尾的空白字符和换行字符
[tempStr stringByReplacingOccurrencesOfString:@"\r" withString:@""];
[tempStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
if (tempStr.length != 0) {
[Mstr appendString:arr[i]];
if (i < [arr count] - 1) {
[Mstr appendString:@"\n"];
}
}
}
return Mstr;
}
NSString 过滤首尾空白、空行,把多换行转为单换行,布布扣,bubuko.com
原文地址:http://blog.csdn.net/alincexiaohao/article/details/38037289