スペース、タブ、改行が連続した NSString があります。それらを1つのスペースだけで再生する方法はありますか? それらを表示するための小さな UIlabel ビューがあります。
1026 次
1 に答える
4
これで試すことができます:
NSString *string = @" spaces in front and at the end ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
ここでのキーは、Apple docの whitespaceAndNewlineCharacterSetです。
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).
于 2012-04-22T13:39:22.240 に答える