Get Date from String

前端 未结 5 580
梦谈多话
梦谈多话 2020-12-16 05:11

Lets say I have one of following strings:

\"Hello, I\'m a String... This is a Stackoverflowquestion!! Here is a Date: 16.03.2013, 02:35 and yeah, plain text          


        
5条回答
  •  攒了一身酷
    2020-12-16 05:20

    For me this code works to get Date from string text contains date.

    var regex = new Regex(@"\d{2}\/\d{2}\/\d{4}");
     foreach (Match m in regex.Matches(line))
     {
      DateTime dt;
      if (DateTime.TryParseExact(m.Value, "MM/dd/yyyy", null, DateTimeStyles.None, out dt))
      remittanceDateArr[chequeNo - 1] = dt.ToString("MM/dd/yyyy");                                   
      rtbExtract.Text = rtbExtract.Text + remittanceDateArr[chequeNo - 1] + "\n";
                                }
    

提交回复
热议问题