C# 中String.Format的问题

2025-05-01 14:04:10
推荐回答(4个)
回答1:

用双重花括号来escape
比如你的问题可以写成这样:string.format("{{'{0}'}}",100)

回答2:

String strID = String.Format(@"{ {0} }","123"); 加上一个@符号试试~~
或者:
String strID = String.Format(@"{ '{0}' }","123");

回答3:

如果你要显示{}z作为你的字符串,你在format方法中只能写一个{},多余的字符串需要写在 “{”+string.format("{0}",100)+"}"

这样写,就没有问题。

回答4:

采用“\”转换就ok了