c# - 如何在c#中拆分带日期的字符串

标签 c# asp.net

我有带日期的字符串,我想用日期和字符串拆分它

例如 : 我有这种类型的字符串数据

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/

相关文章:

c# - 在c#中获取dll程序集的静态文件

c# - MySQL ODBC 存储过程结果缺少列

c# - 如何实现 ASP.Net 复合服务器控件的 ClientInstanceName 属性

c# - 在 Windows Phone ListPicker 控件中绑定(bind)一个大列表

C#将行添加到具有自动增量列的数据表

c# - Windows Server 2008 上的 System.Diagnostics.Process.Start() 问题

c# - ASP.net c#,采用不同参数类型的同名方法

c# - 使用 SAPI(Microsoft 文本到语音 API)中的 Speechlib 作为 Unity AudioSource

c# - 如何创建用于在 C# 中描述对象的自定义语法?

ASP.NET 动态用户控件