Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何删除NSString中多余的空白空间?_Iphone_Objective C_Cocoa Touch_Nsstring - Fatal编程技术网

Iphone 如何删除NSString中多余的空白空间?

Iphone 如何删除NSString中多余的空白空间?,iphone,objective-c,cocoa-touch,nsstring,Iphone,Objective C,Cocoa Touch,Nsstring,有没有一种简单的方法可以删除字符串中的多余空格?我喜欢 NSString *str = @"this string has extra empty spaces"; 结果应该是: NSString *str = @"this string has extra empty spaces"; 谢谢 将所有双空格替换为单个空格,直到字符串中不再有双空格 - (NSString *)stripDoubleSpaceFrom:(NSString *)str { whi

有没有一种简单的方法可以删除字符串中的多余空格?我喜欢

NSString *str = @"this string has extra              empty spaces";
结果应该是:

NSString *str = @"this string has extra empty spaces";

谢谢

将所有双空格替换为单个空格,直到字符串中不再有双空格

- (NSString *)stripDoubleSpaceFrom:(NSString *)str {
    while ([str rangeOfString:@"  "].location != NSNotFound) {
        str = [str stringByReplacingOccurrencesOfString:@"  " withString:@" "];
    }
    return str;
}

谢谢你的回复,fluchtpunkt!我希望会有一句客串之类的:)加油!没有其他直接/书面方式?