zoukankan      html  css  js  c++  java
  • 字符串的系列操作

    /**
    * @param regex
    * 正则表达式字符串
    * @param str
    * 要匹配的字符串
    * @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
    */
    private static boolean match(String regex, String str) {
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(str);
    return matcher.matches();
    }
    
    // 3. 检查字符串重复出现的词
    // 
    // private void btnWord_Click(object sender, EventArgs e)
    // {
    // System.Text.RegularExpressions.MatchCollection matches =
    // System.Text.RegularExpressions.Regex.Matches(label1.Text,
    // 
    // @"(?<word>w+)s+(k<word>)",
    // System.Text.RegularExpressions.RegexOptions.Compiled |
    // System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // if (matches.Count != 0)
    // {
    // foreach (System.Text.RegularExpressions.Match match in matches)
    // {
    // string word = match.Groups["word"].Value;
    // MessageBox.Show(word.ToString(),"英文单词");
    // }
    // }
    // else { MessageBox.Show("没有重复的单词"); }
    // 
    // 
    // }
    // 
    // 4. 替换字符串
    // 
    // private void button1_Click(object sender, EventArgs e)
    // {
    // 
    // string strResult =
    // System.Text.RegularExpressions.Regex.Replace(textBox1.Text,
    // @"[A-Za-z]*?", textBox2.Text);
    // MessageBox.Show("替换前字符:" + "
    " + textBox1.Text + "
    " + "替换的字符:" + "
    "
    // + textBox2.Text + "
    " +
    // 
    // "替换后的字符:" + "
    " + strResult,"替换");
    // 
    // }
    // 
    // 5. 拆分字符串
    // 
    // private void button1_Click(object sender, EventArgs e)
    // {
    // //实例: 甲025-8343243乙0755-2228382丙029-32983298389289328932893289丁
    // foreach (string s in
    // System.Text.RegularExpressions.Regex.Split(textBox1.Text,@"d{3,4}-d*"))
    // {
    // textBox2.Text+=s; //依次输出 "甲乙丙丁"
    // }
    // 
    // }
  • 相关阅读:
    web服务器-Apache
    nginx优化
    nginx下载限速
    nginx-URL重写
    HDU 5358 First One 求和(序列求和,优化)
    HDU 5360 Hiking 登山 (优先队列,排序)
    HDU 5353 Average 糖果分配(模拟,图)
    UVALive 4128 Steam Roller 蒸汽式压路机(最短路,变形) WA中。。。。。
    HDU 5348 MZL's endless loop 给边定向(欧拉回路,最大流)
    HDU 5344 MZL's xor (水题)
  • 原文地址:https://www.cnblogs.com/20gg-com/p/6037530.html
Copyright © 2011-2022 走看看