陈斌彬的技术博客

Stay foolish,stay hungry

OC去掉字符串中左右两边的空格

去掉字符串中所有的空格:

//stringByReplacingOccurrencesOfString字符串替换方法,将空格替换为空
NSString *string = [sourceString stringByReplacingOccurrencesOfString:@" " withString:@""];

去掉左右两边的空格

//去掉左右两边的空格
NSString *string = [sourceString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//去掉左右两边的空格和换行
NSString *string = [sourceString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];