【求助】:如何使用正则式对文本进行查找替换? 例句:“中华人民共和国成立于1949年10月1日,I、U、R、#”查找其中的“1949、10、1、I、U、R、#”然后替换成“中华人民共和国成立于一九四九年十月一日,电流、电压、电阻、号”如何用一句正则式进行查找替换呢?正则 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.IO.StreamReader reader1 = new System.IO.StreamReader("e:\\1.txt",Encoding.Default); string str = @"中华人民共和国成立于1949年10月1日,I、U、R、#"; string strmatch = @"(?is)[\d]+|[a-z]|#"; System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch); System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str); foreach (System.Text.RegularExpressions.Match mm in mc) { MessageBox.Show(mm.Value); } List<string> wordtomatch = new List<string>() { "1949", "10", "1", "I", "U", "R", "#" };List<string> replacewith = new List<string>() { "一九四九", "十", "一", "电流", "电压", "电阻", "号" };wordtomatch.ForEach(x => s = s.Replace(x, replacewith[wordtomatch.FindIndex(y => y == x)])); 谢谢bdmh,若将例句采用string str = Regex.Replace(TextBox1.txt, "查找1949、10、1、I、U、R、#", "替换一九四九、十、一、电流、电压、电阻、号");这样的正则式该如何写呢?TextBox2.txt=”中华人民共和国成立于一九四九年十月一日,电流、电压、电阻、号“ 谢谢caozhy问题解决啦!也非常感谢bdmh!3Q! textBox仿百度、谷歌 下拉列表 怎么识别是机器人来访问? 求救:Winform下的程序--读取Word文档,可能会的不难谢谢了! 我就还有50分了全给你们了,帮解决一下谢谢! winform系统中怎么查看导出或导入的日志? datagrid行提针 今天提供我的一些近期开发的源码和组件,需要的赶快进 有关打印问题,请高手指点,解决了就给分,谢谢! 续帮助,谢谢~ 请教:VS6下的Dependency工具在VS.NET下是什么东东代替了? 求个zpl条码指令 求助专家!!!!! MONO.Cecil.Cil中OpCode的结构里的字段都是什么意思啊
System.IO.StreamReader reader1 = new System.IO.StreamReader("e:\\1.txt",Encoding.Default);
string str = @"中华人民共和国成立于1949年10月1日,I、U、R、#";
string strmatch = @"(?is)[\d]+|[a-z]|#";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str);
foreach (System.Text.RegularExpressions.Match mm in mc)
{
MessageBox.Show(mm.Value);
}
List<string> replacewith = new List<string>() { "一九四九", "十", "一", "电流", "电压", "电阻", "号" };
wordtomatch.ForEach(x => s = s.Replace(x, replacewith[wordtomatch.FindIndex(y => y == x)]));
若将例句采用string str = Regex.Replace(TextBox1.txt, "查找1949、10、1、I、U、R、#", "替换一九四九、十、一、电流、电压、电阻、号");这样的正则式该如何写呢?
TextBox2.txt=”中华人民共和国成立于一九四九年十月一日,电流、电压、电阻、号“
谢谢caozhy
问题解决啦!也非常感谢bdmh!3Q!