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:@" "];
本文介绍了一种使用Objective-C编程语言去除字符串中空白字符的方法。通过将原始字符串分割为组件并过滤掉空组件来实现,最终将有效组件重新组合成一个不含多余空白的新字符串。
8325

被折叠的 条评论
为什么被折叠?



