美文网首页
iOS 字符串过滤空白字符和换行符

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

作者: Daimer | 来源:发表于2017-12-19 18:17 被阅读0次

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

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

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

// 去掉首尾的空白字符

            originalString = [originalStringstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];

// 去掉换行符

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

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

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

// originalString 过滤后的字符串

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

相关文章

网友评论

      本文标题:iOS 字符串过滤空白字符和换行符

      本文链接:https://www.haomeiwen.com/subject/qzsiwxtx.html