<i id='h1oJC'><tr id='h1oJC'><dt id='h1oJC'><q id='h1oJC'><span id='h1oJC'><b id='h1oJC'><form id='h1oJC'><ins id='h1oJC'></ins><ul id='h1oJC'></ul><sub id='h1oJC'></sub></form><legend id='h1oJC'></legend><bdo id='h1oJC'><pre id='h1oJC'><center id='h1oJC'></center></pre></bdo></b><th id='h1oJC'></th></span></q></dt></tr></i><div id='h1oJC'><tfoot id='h1oJC'></tfoot><dl id='h1oJC'><fieldset id='h1oJC'></fieldset></dl></div>

        <bdo id='h1oJC'></bdo><ul id='h1oJC'></ul>

    1. <legend id='h1oJC'><style id='h1oJC'><dir id='h1oJC'><q id='h1oJC'></q></dir></style></legend>
    2. <tfoot id='h1oJC'></tfoot>
    3. <small id='h1oJC'></small><noframes id='h1oJC'>

    4. 如何在.NET中以格式字符串转义大括号(大括号)

      时间:2023-05-20
      <tfoot id='3iNIk'></tfoot>
        <tbody id='3iNIk'></tbody>
        <legend id='3iNIk'><style id='3iNIk'><dir id='3iNIk'><q id='3iNIk'></q></dir></style></legend>

          • <bdo id='3iNIk'></bdo><ul id='3iNIk'></ul>

              <i id='3iNIk'><tr id='3iNIk'><dt id='3iNIk'><q id='3iNIk'><span id='3iNIk'><b id='3iNIk'><form id='3iNIk'><ins id='3iNIk'></ins><ul id='3iNIk'></ul><sub id='3iNIk'></sub></form><legend id='3iNIk'></legend><bdo id='3iNIk'><pre id='3iNIk'><center id='3iNIk'></center></pre></bdo></b><th id='3iNIk'></th></span></q></dt></tr></i><div id='3iNIk'><tfoot id='3iNIk'></tfoot><dl id='3iNIk'><fieldset id='3iNIk'></fieldset></dl></div>

              1. <small id='3iNIk'></small><noframes id='3iNIk'>

                本文介绍了如何在.NET中以格式字符串转义大括号(大括号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                使用string.Format如何对括号进行转义?

                How can brackets be escaped in using string.Format?

                例如:

                String val = "1,2,3"
                String.Format(" foo {{0}}", val);
                

                这个例子没有抛出异常,而是输出字符串foo {0}.

                This example doesn't throw an exception, but it outputs the string foo {0}.

                有没有办法逃脱括号?

                推荐答案

                要输出 foo {1, 2, 3} 你必须这样做:

                For you to output foo {1, 2, 3} you have to do something like:

                string t = "1, 2, 3";
                string v = String.Format(" foo {{{0}}}", t);
                

                要输出一个 { 你使用 {{ 并且要输出一个 } 你使用 }}.

                To output a { you use {{ and to output a } you use }}.

                或者现在,您也可以像这样使用 C# 字符串插值(C# 6.0 中提供的一项功能)

                转义括号:字符串插值 $("").这是 C# 6.0 的新特性.

                Escaping brackets: String interpolation $(""). It is new feature in C# 6.0.

                var inVal = "1, 2, 3";
                var outVal = $" foo {{{inVal}}}";
                // The output will be:  foo {1, 2, 3}
                

                这篇关于如何在.NET中以格式字符串转义大括号(大括号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:构建失败.错误:“路径"不能是空字符串(“")或以空字符开头 下一篇:C#将int转换为带有填充零的字符串?

                相关文章

                  <bdo id='32QqG'></bdo><ul id='32QqG'></ul>

                <small id='32QqG'></small><noframes id='32QqG'>

                1. <i id='32QqG'><tr id='32QqG'><dt id='32QqG'><q id='32QqG'><span id='32QqG'><b id='32QqG'><form id='32QqG'><ins id='32QqG'></ins><ul id='32QqG'></ul><sub id='32QqG'></sub></form><legend id='32QqG'></legend><bdo id='32QqG'><pre id='32QqG'><center id='32QqG'></center></pre></bdo></b><th id='32QqG'></th></span></q></dt></tr></i><div id='32QqG'><tfoot id='32QqG'></tfoot><dl id='32QqG'><fieldset id='32QqG'></fieldset></dl></div>

                  1. <legend id='32QqG'><style id='32QqG'><dir id='32QqG'><q id='32QqG'></q></dir></style></legend><tfoot id='32QqG'></tfoot>