首页 > 其他 > 详细

使用正则表达式替换字符串

时间:2018-11-30 18:52:20      阅读:147      评论:0      收藏:0      [点我收藏+]

实现效果:

  技术分享图片

知识运用:

  Regex类的Replace()方法:用于替换在指定字符串内匹配正则式的字符串为某字符串

  public static string Replace(string input,string pattern,string replacement)

  input   要搜索匹配项的字符串

  pattern    要匹配的正则表达式模式

  replacement    要替换的为结果的字符串

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            string result = System.Text.RegularExpressions.
                Regex.Replace(textBox1.Text,"[A-Za-z]+",textBox2.Text);
            MessageBox.Show("原字符串:\n"+textBox1.Text+"\n"+
                    "替换为:\n"+textBox2.Text+"\n"+"替换后:\n"+result);
        }

 

使用正则表达式替换字符串

原文:https://www.cnblogs.com/feiyucha/p/10045778.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!