string a = "5322/26.81.12.31.00.01"; a.Replace("/", "").Replace(".", "")
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions;namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Regex rg=new Regex(this.textBox2.Text.Trim()); Match mt; mt=rg.Match(this.textBox1.Text.Trim()); if (mt.Success) { label1.Text = mt.Groups[0].ToString(); } } } }
转换为数字集合的话你可以string a = "5322/26.81.12.31.00.01"; a.Replace("/", "").Replace(".", "") 也可以直接(\d{4})/(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2})using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions;namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Regex rg = new Regex(this.textBox2.Text.Trim()); Match mt; mt = rg.Match(this.textBox1.Text.Trim()); if (mt.Success) { label1.Text = ""; for (int i = 1; i < mt.Groups.Count; i++) { label1.Text += mt.Groups[i].ToString(); } } } } }
不好意思啊,我没说清楚
把红色字符截取出来并转换成 5322268112310001 这种格式的
我看例子 写了个这样的
Regex reg = new Regex(@"(?is)[\d]{4}[\d]{2} [\d]{2} [\d]{2} [\d]{2} [\d]{2}"); 不知道怎么截取5322/26 和.符合。
a.Replace("/", "").Replace(".", "")
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Regex rg=new Regex(this.textBox2.Text.Trim());
Match mt;
mt=rg.Match(this.textBox1.Text.Trim());
if (mt.Success)
{
label1.Text = mt.Groups[0].ToString();
}
}
}
}
a.Replace("/", "").Replace(".", "")
也可以直接(\d{4})/(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2})using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Regex rg = new Regex(this.textBox2.Text.Trim());
Match mt;
mt = rg.Match(this.textBox1.Text.Trim());
if (mt.Success)
{
label1.Text = "";
for (int i = 1; i < mt.Groups.Count; i++)
{
label1.Text += mt.Groups[i].ToString();
}
}
}
}
}