- (NSString *)filterBlankAndBlankLines:(NSString *)str
{
NSMutableString *Mstr = [NSMutableString string];
NSArray *arr = [str componentsSeparatedByString:@" "];
for (int i = 0; i < arr.count; i++) {
NSString *tempStr = (NSString *)arr[i];
[tempStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; //去除掉首尾的空白字符和换行字符
[tempStr stringByReplacingOccurrencesOfString:@" " withString:@""];
[tempStr stringByReplacingOccurrencesOfString:@" " withString:@""];
if (tempStr.length != 0) {
[Mstr appendString:arr[i]];
if (i < [arr count] - 1) {
[Mstr appendString:@" "];
}
}
}
return Mstr;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。