转义 String.Format 占位符
我有以下字符串,
"ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8"
我想这样使用它
String.Format("ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8", MyValue)
WHERE MyValue would replace ID={0}
,但这会引发 System.FormatException
。显然,这是因为 {1CC88B01-E60F-45D1-8B3C-28852574156D} guid
使用了 string.format
占位符值。现在我可以简单地根据需要拆分字符串调用 string.format()
并将其重新连接在一起,但是是否有某种方法可以通过某种方式“转义”占位符值来避免这样做?
I have the following string
"ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8"
I would like to use it as such
String.Format("ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8", MyValue)
WHERE MyValue would replace ID={0}
However this throws a System.FormatException
. Obviously this is because of the {1CC88B01-E60F-45D1-8B3C-28852574156D} guid
that uses the string.format
placeholder value. Now I can simply split the string call string.format()
as required and concat it back together but is there perhaps some way I can avoid doing that by "escaping" the placeholder value somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你只需要加倍大括号:
You just need to double the braces:
使用双 {{ 或 }} 字符来转义它们。
Use double {{ or }} characters to escape them.