读书人

除开NSString中空格

发布时间: 2013-09-30 09:50:49 作者: rapoo

去掉NSString中空格

NSString *s = @"this is    a  string    with lots  of     white space"; NSArray *comps = [s componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];  NSMutableArray *words = [NSMutableArray array]; for(NSString *comp in comps) {   if([comp length] > )) {     [words addObject:comp];   } }  NSString *result = [words componentsJoinedByString:@" "]; 

?

读书人网 >移动开发

热点推荐