Uni*_*orn 6 iphone cocoa-touch objective-c nsstring
是否有一种简单的方法来删除字符串中的额外空格?就像......
NSString *str = @"this string has extra empty spaces";
Run Code Online (Sandbox Code Playgroud)
结果应该是:
NSString *str = @"this string has extra empty spaces";
Run Code Online (Sandbox Code Playgroud)
谢谢!
Mat*_*uch 16
用一个空格替换所有双空格,直到字符串中不再有双重空格.
- (NSString *)stripDoubleSpaceFrom:(NSString *)str {
while ([str rangeOfString:@" "].location != NSNotFound) {
str = [str stringByReplacingOccurrencesOfString:@" " withString:@" "];
}
return str;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3577 次 |
| 最近记录: |