我想要一个替换 的
想要替换把这里内容有\n的替换掉
外面的不替换只替换code里面的,怎 么写啊

解决方案 »

  1.   

    Contents = Contents.Replace(@"\n","");
      

  2.   

    static void Main(string[] args)
            {
               
                string test=@"我想要一个替换 的 
    想要替换[code=c#]把这里内容有\n的
    替换掉 
    外面的不替换只替换code里面的,怎 么写啊";            Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);            string ret = r1.Match(test).Value;
                    ret=r1.Replace(test,new MatchEvaluator(CapText));        }        static string CapText(Match m)
            {
                string x = m.ToString().Replace("\\n","(我是\\n)");           
                return x;
            }[/code]
      

  3.   

      static void Main(string[] args)
            {
                   string test=@"我想要一个替换 的 
    想要替换[code=W#]把这里内容有\n的
    替换掉[/code] 
    外面的不替换只替换code里面的,怎 么写啊";            Regex r1 = new Regex(@"\[code=[\s\S]*\[/code\]", RegexOptions.IgnoreCase | RegexOptions.Multiline);            string ret = r1.Match(test).Value;
                    ret=r1.Replace(test,new MatchEvaluator(CapText));        }        static string CapText(Match m)
            {
                // Get the matched string.
                string x = m.ToString().Replace("\\n","(我是\\n)");
                // If the first char is lower case...
                
                return x;
            }