由于您不想使用正则表达式,只需在空间上拆分字符串,然后使用DateTime.TryParseExact
查看是否有任何字符串被解析为DateTime
string str = "Hello I am a Coder, My DOB is 12/09/2011";
string[] array = str.Split();//splits on space
string dateFormat = "M/d/yyyy"; //works with both single digit and double digit
//(day/month) for parsing
//or d/M/yyyy depending your date culture
DateTime tempDateTime;
var result = array.FirstOrDefault(r =>
DateTime.TryParseExact
(r,
dateFormat,
CultureInfo.InvariantCulture,
DateTimeStyles.NoCurrentDateDefault,
out tempDateTime));
您result
将包含 Date 字符串,并且您tempDateTime
将包含 parsed DateTime
。