close
class TestRegularExpressions { static void Main() { string[] sentences = { "cow over the moon", "Betsy the Cow", "cowering in the corner", "no match here" }; string sPattern = "cow"; 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(); } } } }
輸出
cow over the moon (match for 'cow' found) Betsy the Cow (match for 'cow' found) cowering in the corner (match for 'cow' found) no match here
全站熱搜