(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:@""];