怎嘛在webconfig里写意个正则,给指定的一个字加上链接

解决方案 »

  1.   

    读取web.config
    string webconfig = 读出来;
    regex urlregex = new regex(@"(http:\/\/([\w.]+\/@)\s*)",
                 regexoptions.ignorecase| regexoptions.compiled);
    strcontent = urlregex.replace(webconfig,
                 "<a href=/knowskycom/\"\" target=\"_blank\"></a>");
      

  2.   


    string webconfig = 读出来;
    regex urlregex = new regex(@"(http:\/\/([\w.]+\/@)\s*)",
      regexoptions.ignorecase| regexoptions.compiled);
    strcontent = urlregex.replace(webconfig,
      "<a href=\"\" target=\"_blank\"></a>");替换完之后在会回写到web.config
      

  3.   


    string webconfig = 读出来;//你先把webconfig的内容读出来,就像读取xml、txt一样
    regex urlregex = new regex(@"(http:\/\/([\w.]+\/@)\s*)",//@"(http:\/\/([\w.]+\/@)\s*)就是你要加链接的文字
      regexoptions.ignorecase| regexoptions.compiled);
    strcontent = urlregex.replace(webconfig,
      "<a href=\"\" target=\"_blank\"></a>");//这就是加完链接之后的webconfig,你在会写到webconfig中很清楚了吧