Iphone 替换连续空格、制表符、换行符集

Iphone 替换连续空格、制表符、换行符集,iphone,ios,nsstring,Iphone,Ios,Nsstring,我有一个连续空格、制表符、换行符的字符串。有没有办法只在一个空间内重播?我有一个小的UIlabel视图来显示它们。您可以尝试以下方法: NSString *string = @" spaces in front and at the end "; NSString *trimmedString = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAnd

我有一个连续空格、制表符、换行符的字符串。有没有办法只在一个空间内重播?我有一个小的UIlabel视图来显示它们。

您可以尝试以下方法:

NSString *string = @" spaces in front and at the end ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
                              [NSCharacterSet whitespaceAndNewlineCharacterSet]];
这里的关键是来自Apple的Whitespace和NewLineCharacterSet:


举一个你的例子是的,我知道这个方法。但是我想在我们的字符串中间修剪空白,就像“中间的空格”一样。
Returns a character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).