110,538
社区成员
发帖
与我相关
我的任务
分享
if (fileName.Contains("BTG"))
{
for (int i = 0; i < listBox4.Items.Count; i++)
{
Regex reg = new Regex(@"(?is)[\d]{4}_[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}", RegexOptions.IgnoreCase);
Match mc = r.Match(this.listBox4.Items[i].ToString());
foreach (Match m in mc)
{
this.listBox2.Items.Add(m.Groups[0].Value.Replace("_", "").Replace(".", "")));
}
}
}
if (fileName.Contains("BTG"))
{
for (int i = 0; i < listBox4.Items.Count; i++)
{
Regex reg = new Regex(@"(?is)[\d]{4}_[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}");
MatchCollection mc = reg.Matches(this.listBox4.Items[i].ToString());
foreach (Match m in mc)
{
this.listBox2.Items.Add(Regex.Replace(this.listBox4.Items[i].ToString(), @"\D", string.Empty));
}
}
}
我这段代码是什么问题呢? 取出来后怎么是2533..... 多了个2呢?
if (fileName.Contains("BTG"))
{
for (int i = 0; i < listBox4.Items.Count; i++)
{
Regex reg = new Regex(@"(?is)[\d]{4}_[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}");
MatchCollection mc = reg.Matches(this.listBox4.Items[i].ToString());
foreach (Match m in mc)
{
this.listBox2.Items.Add(Regex.Replace(this.listBox4.Items[i].ToString(), @"\D", string.Empty));
}
}
}
var str = "B_F_SENSUS_2G_5322_56.81.13.51.01.28";
Regex r = new Regex(@"(?is)[\d]{4}_[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}.[\d]{2}", RegexOptions.IgnoreCase);
Match m = r.Match(str);
while (m.Success)
{
var test = m.Groups[0].Value.Replace("_", "").Replace(".", "");
//输出5322568113510128
MessageBox.Show(test);
}
已测试。