首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

除开NSString中空格

2013-09-30 
去掉NSString中空格NSString *s @this isastringwith lotsofwhite space NSArray *comps [s compon

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

?

热点排行