版权声明:本文为博主原创文章,未经博主允许不得转载。[email protected] 技术讨论群:536739494 https://blog.csdn.net/Nathan1987_/article/details/82348495
1.去掉字符串两端的空格及回车
- (NSString *)removeSpaceAndNewline:(NSString *)str{
NSString *temp = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *text = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
return text;
}
2.去掉所有的空格及字符串
- (NSString *)removeSpaceAndNewline:(NSString *)str{
NSString *temp = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
return temp;
}