简体   繁体   English

从字符串中提取日期,没有空格的字符串

[英]Extract a Date from a String, String without Space

string s = "ElectricityBillPayment10/1/21 - 10/31/21";字符串 s = "ElectricityBillPayment10/1/21 - 10/31/21";

Extract only date from string仅从字符串中提取日期

Since I don't know the exact format possibilites of your string I simply added a Regex that searches for all dates in your example formats and extracts them out of the string:由于我不知道您的string的确切格式可能性,我只是添加了一个正则Regex ,用于搜索您的示例格式中的所有日期并将它们从字符串中提取出来:

string s = "ElectricityBillPayment10/1/21 - 10/31/21";
var regex = new Regex(@"\d{1,2}/\d{1,2}/\d+");
var dates = regex.Matches(s).Select(match => match.Value).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM