c#正则应用

 public   string   regexDate(string   str)  
  {  
  return   Regex.Replace(str,"'(?<year>//d{4})-(?<month>//d{1,2})-(?<day>//d{1,2})'","To_Date('${year}-${month}-${day}','yyyy-mm-dd')",RegexOptions.Multiline);    
  }  

 

有些时候我偶们希望在正则表达式的替换中对替换的字符换进行简单的处理,比如把所有的A依次替换为B1、B2、B3……这就需在替换时对字符串进行处理,其实这个很简单,用C#中的MatchEvaluator委托就可以了。简单的示例如下:

引用内容:
    private static int i = 0;

    public static string ParseToHTML(string ubbString)
    {
        Regex rgx;
        string htmlString = "";

        MatchEvaluator me = new MatchEvaluator(AddOne);
        rgx = new Regex(@"/[code/](.*?)/[//code/]");
        htmlString = rgx.Replace(htmlString, me);

        return htmlString;
    }

    public static string AddOne(Match m)
    {
        string code = m.Value.Substring(6, m.Value.Length - 13);
        string codeString = @"<textarea name='code" + i + "' class='code_text'>" + code + "</textarea></div><br />";
        i++;
        return codeString;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值