C# · 12月 20, 2021

判断一个字符串是否是数字

<div class=”cnblogs_code”>

IsNum( </span><span style=”color: #0000ff;”&gt;string</span> Rx = <span style=”color: #800000;”&gt;@”</span><span style=”color: #800000;”&gt;^[1-9]\d*$</span><span style=”color: #800000;”&gt;”</span><span style=”color: #000000;”&gt;; </span><span style=”color: #0000ff;”&gt;if</span><span style=”color: #000000;”&gt; (Regex.IsMatch(Str,Rx)) { </span><span style=”color: #0000ff;”&gt;return</span> <span style=”color: #0000ff;”&gt;true</span><span style=”color: #000000;”&gt;; } </span><span style=”color: #0000ff;”&gt;else</span><span style=”color: #000000;”&gt; { </span><span style=”color: #0000ff;”&gt;return</span> <span style=”color: #0000ff;”&gt;false</span><span style=”color: #000000;”&gt;; } }</span></pre>