你可以使用正則表達式來做到這一點:如果你想
void Main()
{
var regex = new Regex(@"(January|February|March|April|May|June|July|August|September|October|November|December) \d{2}, \d{4}");
string test1 = "Lorem Ipsum February 01, 2012";
string test2 = "Lorem Ipsum Badmonth 01, 2012";
regex.Match(test1).Dump();
regex.Match(test2).Dump();
}
搜索爲不區分大小寫(將於2月或2月使用)替換爲:
var regex = new Regex(@"(January|February|March|April|May|June|July|August|September|October|November|December) \d{2}, \d{4}", RegexOptions.IgnoreCase);
或(他們究竟做同樣的事情)
var regex = new Regex(@"(?i)(January|February|March|April|May|June|July|August|September|October|November|December) \d{2}, \d{4}");
當循環迭代,然後我中C ==收到錯誤下一次「」。它說,指數走出束縛錯誤 – user3477335
的我想它out..Its工作now..Thanks! – user3477335