1.去掉首尾空格和换行符 [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet] ]
2.只去掉首尾空格:
[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ]