打印

[NET精华教程] .net教程:老外编的程序(三)--正则表达式的demo

.net教程:老外编的程序(三)--正则表达式的demo

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 + "]");
   &nb




TOP

返回顶部
AYBlue

Processed in 0.050170 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-8 10:55 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP