2011-07-27 13 views
0

"%d"、 "%"、 "d"を結合して9を行ったところで、次のようにしたいとします。< ---分割する理由があります。つまり、%x%d%g%f私はループだけ "xdgf"NSString stringWithFormat "%d"の代わりに "%" "d" 4?

lbl.text =[NSString stringWithFormat:@"%@%@", @"%", @"d", 9]; <<--errors 
  • 所望の出力が "9" < -----

です

+0

希望の出力は何ですか? – csano

答えて

2

おかげでのみ最初の引数は形式ですので、あなた生成された書式文字列を取得するには別のstringWithFormat:が必要です。だから、のようなもの:

bl.text = [NSString stringWithFormat:[NSString stringWithFormat:@"%@%@", @"%", @"d"], 9]; 
                   //^OR @"%%%@", @"%d" if only the 'd' is variable 

それはNSScannerまたは-[NSNumber stringValue]か何かのように見えますが、タスクのこの種のに適しだろう。

+0

これは正しいですが、私はOPが狂っていると思います。 :) – jtbandes