LoginSignup
2
1

More than 5 years have passed since last update.

[C#]string.Formatで文字列に波括弧(中括弧)を入れる方法

Last updated at Posted at 2016-07-07

string.Formatでは、波括弧{}は書式設定の先頭または末尾として処理される。

string.Format("{HOGEHOGE{0}}", "FOO");

例えば上記のような処理では、先頭と末尾の波括弧のせいでFormatExceptionになってしまう。
書式設定ではなく、通常の文字列として認識させたい場合は波括弧をさらに重ねてエスケープする。

string.Format("{{HOGEHOGE{0}}}", "FOO");
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1