111,119
社区成员
发帖
与我相关
我的任务
分享private static void TestRegex05()
{
string date_str = "6.1~7.24";
Match m = System.Text.RegularExpressions.Regex.Match(date_str, @"(?<from_Month>\d+)\.(?<from_Day>\d+)~(?<to_Month>\d+)\.(?<to_Day>\d+)");
if (m.Success)
{
Console.WriteLine(m.Groups["from_Month"].Value);
Console.WriteLine(m.Groups["from_Day"].Value);
Console.WriteLine(m.Groups["to_Month"].Value);
Console.WriteLine(m.Groups["to_Day"].Value);
}
}string date_str = "6.1~7.24";
string[] s1 = date_str.Split("~");
string[] s2 = s1[1].Split(".");
MessageBox.Show(s2[0]); // 7
MessageBox.Show(s2[1]); // 24string date_str = "6.1~7.24";
string[] arr1 = date_str.Split('~');
string[] arr2 = arr1[1].Split('.');
string month = arr2[0];
string day = arr2[1];