<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 如何:使用正則表達式搜索字符串(C# 編程指南) 可以使用 [System.Text.RegularExpressions.Regex](https://msdn.microsoft.com/zh-CN/library/system.text.regularexpressions.regex.aspx) 類搜索字符串。這些搜索有的非常簡單,有的復雜到需要完全使用正則表達式。以下是使用 [Regex](https://msdn.microsoft.com/zh-CN/library/system.text.regularexpressions.regex.aspx) 類搜索字符串的兩個示例。有關更多信息,請參見[.NET Framework 正則表達式](https://msdn.microsoft.com/zh-CN/library/hs600312.aspx)。 以下代碼是一個控制臺應用程序,用于對數組中的字符串執行簡單的不區分大小寫的搜索。給定要搜索的字符串和包含搜索模式的字符串后,靜態方法 [Regex.IsMatch](https://msdn.microsoft.com/zh-CN/library/ktzf2d23.aspx) 將執行搜索。在本例中,使用第三個參數指示忽略大小寫。有關更多信息,請參見[System.Text.RegularExpressions.RegexOptions](https://msdn.microsoft.com/zh-CN/library/system.text.regularexpressions.regexoptions.aspx)。 ``` class TestRegularExpressions { static void Main() { string[] sentences = { "C# code", "Chapter 2: Writing Code", "Unicode", "no match here" }; string sPattern = "code"; foreach (string s in sentences) { System.Console.Write("{0,24}", s); if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { System.Console.WriteLine(" (match for '{0}' found)", sPattern); } else { System.Console.WriteLine(); } } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } } /* Output: C# code (match for 'code' found) Chapter 2: Writing Code (match for 'code' found) Unicode (match for 'code' found) no match here */ ``` 以下代碼是一個控制臺應用程序,此程序使用正則表達式驗證數組中每個字符串的格式。驗證要求每個字符串具有電話號碼的形式,即用短劃線將數字分成三組,前兩組各包含三個數字,第三組包含四個數字。這是使用正則表達式 ^\\d{3}-\\d{3}-\\d{4}$ 完成的。有關更多信息,請參見[正則表達式語言 - 快速參考](https://msdn.microsoft.com/zh-CN/library/az24scfc.aspx)。 ``` class TestRegularExpressionValidation { static void Main() { string[] numbers = { "123-555-0190", "444-234-22450", "690-555-0178", "146-893-232", "146-555-0122", "4007-555-0111", "407-555-0111", "407-2-5555", }; string sPattern = "^\\d{3}-\\d{3}-\\d{4}$"; foreach (string s in numbers) { System.Console.Write("{0,14}", s); if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern)) { System.Console.WriteLine(" - valid"); } else { System.Console.WriteLine(" - invalid"); } } // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } } /* Output: 123-555-0190 - valid 444-234-22450 - invalid 690-555-0178 - valid 146-893-232 - invalid 146-555-0122 - valid 4007-555-0111 - invalid 407-555-0111 - valid 407-2-5555 - invalid */ ``` ## 請參閱 [System.Text.RegularExpressions.Regex](https://msdn.microsoft.com/zh-CN/library/system.text.regularexpressions.regex.aspx) [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [字符串(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/ms228362.aspx) [.NET Framework 正則表達式](https://msdn.microsoft.com/zh-CN/library/hs600312.aspx) [正則表達式語言 - 快速參考](https://msdn.microsoft.com/zh-CN/library/az24scfc.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看