iOS开发之字符串去掉首尾空格换行
作者:互联网
(1)去掉字符串首尾空格的方法:
NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
(2)去掉字符串首尾换行的方法:
NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
(3)去掉字符串首尾空格和换行的方法:
NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
(4)替换字符串内所有空格的方法:
NSString *str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
(5)替换字符串内所有空格的方法:
NSString *str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
标签:NSCharacterSet,换行,iOS,空格,NSString,str,字符串,首尾 来源: https://www.cnblogs.com/hecanlin/p/12165846.html