`
wanggp
  • 浏览: 147710 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics