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

    <small id='IWrJy'></small><noframes id='IWrJy'>

    <tfoot id='IWrJy'></tfoot>

      • <bdo id='IWrJy'></bdo><ul id='IWrJy'></ul>
      <legend id='IWrJy'><style id='IWrJy'><dir id='IWrJy'><q id='IWrJy'></q></dir></style></legend>

      检查 FormatString 的简单方法是否有效?

      时间:2023-05-21

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

            <tbody id='cl1xb'></tbody>
          • <legend id='cl1xb'><style id='cl1xb'><dir id='cl1xb'><q id='cl1xb'></q></dir></style></legend>
              <bdo id='cl1xb'></bdo><ul id='cl1xb'></ul>
              <tfoot id='cl1xb'></tfoot>
              1. <small id='cl1xb'></small><noframes id='cl1xb'>

                本文介绍了检查 FormatString 的简单方法是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                有没有一种简单的方法来检查格式字符串是否有效?例如下面是我们用来测试数字格式字符串的代码;

                Is there an easy way to check if a format string is valid? For example the following is code that we use to test a number format string;

                public static bool IsValidFormatStringNumber(string FormatString)
                {
                    try
                    {
                        const decimal number = 0.056m;
                        var formattedNumber = number.ToString(FormatString);
                        return formattedNumber.Length > 0;
                    }
                    catch
                    {
                        return false;
                    }
                }
                

                我们正在尝试捕获异常或确定结果字符串是否没有长度.但是,此测试失败,因为hsibbur"(任何垃圾)的格式字符串会导致字符串hsaibbur",它有长度.

                We're trying to catch an exception or determine if the resulting string has no length. This test fails however as a format string of "hsibbur" (Any rubbish) results in a string of "hsaibbur", which has length.

                我们想对百分比和日期格式字符串做同样的测试.

                We want to do the same test for Percent and Date format string.

                推荐答案

                如果你只想检查 标准格式字符串,只需检查您的格式字符串是否属于该列表.

                If you just want to check for standard format strings, just check that your format strings are part of that list.

                如果您想检查 自定义格式字符串 (不是其他"或文字字符串"),您可能可以制作一个正则表达式来做到这一点.

                If you want to check for custom format strings (that are not "Other" or "Literal strings"), you can probably craft a regex to do it.

                除此之外,由于格式字符串可以是任意字符串,我认为验证甚至适用.

                Other than that, since format strings can be arbitrary strings, I don't think validation even applies.

                这篇关于检查 FormatString 的简单方法是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:asp:repeater - 部分更改的标题 下一篇:德国文化 - 用逗号从 JSON 中获取双数

                相关文章

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

                  <small id='eVbSr'></small><noframes id='eVbSr'>

                  • <bdo id='eVbSr'></bdo><ul id='eVbSr'></ul>

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