我想拆分我的字符串s1 = 6/28/2010 4:46:36 PM
和s2 = 16:46:36.5013946
. 并将它们连接到 new s3 = 20010062816463650
。但是当我拆分 s2. 我的正则表达式不起作用。我现在被暂停了。
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace ConAppTest
{
class Program
{
static void Main(string[] args)
{
string s1 = ""; // date
string s2 = ""; // time
Console.WriteLine("{0}", DateTime.Now);
s1 = DateTime.Now.ToString();
Console.WriteLine("{0}", DateTime.Now.TimeOfDay);
s2 = DateTime.Now.TimeOfDay.ToString();
Regex regex1 = new Regex(@" |:|/"); //6/28/2010 2:19:21 PM
char[] separators1 = { ' ', '/' };
foreach (string sub1 in regex1.Split(s1))
{
Console.WriteLine("Word1: {0}", sub1);
}
Regex regex2 = new Regex(@":|."); //14:19:21.8771215
char[] separators2 = { ':', '.' };
foreach (string sub2 in regex2.Split(s2))
{
Console.WriteLine("Word2: {0}", sub2);
}
}
}
}
//output
//6/28/2010 4:46:36 PM
//16:46:36.5013946
//Word1: 6
//Word1: 28
//Word1: 2010
//Word1: 4
//Word1: 46
//Word1: 36
//Word1: PM
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2:
//Word2: