私は次のC#/を再現することができますNET:のObjective-C/Cocoaの中はココア文字列フォーマット対純
//A
String.Format("There are {0} cats in my {1} and no {2}", 2, "house", "dogs");
:
//B
[NSString stringWithFormat:@"There are %d cats in my %@ and no %@", 2, "house", "dogs"];
しかし、私はこれを行うことはできません。
Objective-Cの中 :
//D
[NSString stringWithFormat:@"I have %d dogs in my house. My %d dogs are very nice, but it is hard to walk %d dogs at the same time.", numDogs];
はprintf形式などを使用しているためです。これを行うより高度な方法がありますか?文字列解析でKVCを実行する方法はありますか?
これは私が欲しいものを技術的には次のとおりです。
[player setValue:@"Jimmy" [email protected]"PlayerName"];
//later
[NSString stringWithMagicFormat:@"<PlayerName> sat on a bench in the middle of winter, and <GenderPronoun> felt very cold." andPlayer:player];
// or
[NSString stringwithMagicFormat: playerEnteredStringWithTagInIt andPlayer:player];
をしかし、私はのために解決されます:(。man 3 printf
を参照)のおかげで、
+1 internets DUH。 KVCについて何も投稿していない場合、私はこれを受け入れます。 –
@Wevah、これはC99に準拠していませんか? ["C99標準には、Single Unix仕様に由来する '$'を使用したスタイルは含まれていません。]](http://linux.die.net/man/3/printf) –
なぜそれが必要なのですか?あなたは 'gnu99'を使用できませんか? OS X用にコンパイルしている場合(これは "ココア"とタグ付けしていると仮定します)、OS Xのマニュアルページにはそのような警告はありません。 – Wevah