我有带日期的字符串,我想用日期和字符串拆分它
例如 :
我有这种类型的字符串数据
9/23/2013/marking abandoned based on notes below/DB
12/8/2012/I think the thid is string/SG
我想把它变成这样
9/23/2013 marking abandoned based on notes below/DB
12/8/2013 I think the thid is string/SG
所以,我不知道如何拆分这些字符串并存储在表的不同列中。 请帮助我。
最佳答案
string[] vals = { "9/23/2013/marking abandoned based on notes below/DB",
"12/8/2012/I think the thid is string/SG" };
var regex = @"(\d{1,2}/\d{1,2}/\d{4})/(.*)";
var matches = vals.Select(val => Regex.Match(vals, regex));
foreach (var match in matches)
{
Console.WriteLine ("{0} {1}", match.Groups[1], match.Groups[2]);
}
打印:
9/23/2013 marking abandoned based on notes below/DB
12/8/2012 I think the thid is string/SG
(\d{1,2}/\d{1,2}/\d{4})/(.*)
分解为
(\d{1,2}/\d{1,2}/\d{4})
:\d{1,2}
- 匹配任何一位或两位数字/
- 匹配一个/
符号\d{4}
- 匹配四位数(...)
- 表示第一组
(.*)
- 匹配所有其他内容并创建第二组
关于c# - 如何在c#中拆分带日期的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19686407/