
(1)系统去首尾空格方法,使用NSString中的str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]方法只是去掉左右两边的空格;
(2)替换的方法,使用NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@" " withString:@""];可以去掉空格,注意此时生成的strUrl是autorelease属性的,不要妄想对strUrl进行release操作。
//对比
NSString *temptext = [messageTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *text = [temptext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
第1行是去除两端的空格
第2行是去除回车
网友评论