zoukankan      html  css  js  c++  java
  • 使用正则表达式替换字符串

    实现效果:

      

    知识运用:

      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("原字符串:
    "+textBox1.Text+"
    "+
                        "替换为:
    "+textBox2.Text+"
    "+"替换后:
    "+result);
            }
    
  • 相关阅读:
    内部类
    this关键字
    封装
    构造方法
    类图
    StringBuffer
    String
    导包
    包名规范
    带参数的方法
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10045778.html
Copyright © 2011-2022 走看看