我需要在字符串中搜索和解析日期时间(根据当前文化格式化)。
目前我能想到的最好的是:
string text = String.Format("Time is {0}; all's well", DateTime.Now);
DateTime date = new DateTime();
for (int start = 0; start < text.Length - 1; start++)
for (int length = text.Length - start; length > 0; length--)
if (DateTime.TryParse(text.Substring(start, length), out date))
return date;
有没有更聪明的方法来做到这一点?