iOS 字符串过滤空白字符和换行符

2017-12-19  本文已影响0人  Daimer

//去除掉首尾的空白字符和换行字符

            NSString * originalString = subTitle;  // 想要过滤的字符串

            NSLog(@"过滤前---%@",originalString);

// 去掉首尾的空白字符

            originalString = [originalStringstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];

// 去掉换行符

            originalString = [originalStringstringByReplacingOccurrencesOfString:@"\r"withString:@""];

            originalString = [originalStringstringByReplacingOccurrencesOfString:@"\n"withString:@""];

            originalString = [originalStringstringByReplacingOccurrencesOfString:@"\t"withString:@""];

// originalString 过滤后的字符串

            NSLog(@"过滤后---%@",originalString);
上一篇 下一篇

猜你喜欢

热点阅读