s1 = 6/28/2010 4:46:36 PM
및 s2 = 16:46:36.5013946
문자열을 분할하고 싶습니다. 을 입력하고 새 s3 = 20010062816463650
에 연결합니다. 하지만 s2를 나눌 때. 내 정규식이 작동하지 않습니다. 나는 지금 멈추었다. 일반 식에 사용되는 경우는Regex 표현식 및 문자열 C#에서 질문
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:
좋은 해결책을 가르쳐 주셔서 감사합니다. –