首页 > 开发 > 综合 > 正文

老外编的程序(三)--正则表达式的Demo

2024-07-21 02:20:12
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

using system.text.regularexpressions;

class test {
    static string captext(match m) {
    // get the matched string
    string x = m.tostring();
    // if the first char is lower case
    if (char.islower(x[0])) {
        // capitalize it
        return char.toupper(x[0]) + x.substring(1, x.length-1);
    }
    return x;
    }
    
    static void main() {
    string text = "four score and seven years ago";
    system.console.writeline("text=[" + text + "]");
    string result = regex.replace(text, @"/w+",
                      new matchevaluator(test.captext));
    system.console.writeline("result=[" + result + "]");
    }
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表