Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
string str = "({{0}})"; int i = 0; string str2 = string.Format(str, i++); string str3 = string.Format(str, i++);
str3 が ({1}) ではなく ({0}) なのはなぜですか?
中括弧をエスケープしたため、特別な意味はありません。ドキュメントから:
format で 1 つのリテラル中かっこ文字を指定するには、先頭または末尾の中かっこ文字を 2 つ指定します。つまり、"{{"または"}}".
"{{"
"}}"
プログラムを単純化しても、問題を実証できます。
Console.WriteLine("{{0}}", 1);
出力:
{0}
オンラインでの動作を確認してください: ideone
必要な出力を取得するには、その後に{{続いて{0}最後に使用する必要があり}}ます。
{{
}}
string str = "({{{0}}})";