string s="#我爱中国china#士大夫方式大幅士#大夫#sdf";
如何把把s中替换为s1="#我爱中国china#";
s2="士大夫方式大幅士";
s3="#大夫#";
s4="sdf";
即是我要对"#"号之间的字符做处理对s1,及s3处理后
再组成s=s1+s2+s3+s4;

解决方案 »

  1.   

    先Split成数组,然后再分可能会好些
      

  2.   

    s.sqlit(new char[]{'#'})先分割字符串
      

  3.   

    用一个数组 储存  Array arrStr = s.sqlit('#');arrStr 的值依次应该是    {"","我爱中国china","士大夫方式大幅士","大夫","sdf"}
      

  4.   

    split他得不到#符号
    如果需要这个要在split后的数组中自己加了
      

  5.   

    try...            string test = "#我爱中国china#士大夫方式大幅士#大夫#sdf";
                Regex reg = new Regex(@"#[^#]*#|[^#]+");
                MatchCollection mc = reg.Matches(test);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Value + "\n";
                }
      

  6.   

    string[] arrStr = s.sqlit('#'); 
      

  7.   

    string s = "#我爱中国china#士大夫方式大幅士#大夫#sdf";
    string result =string.Join("", s.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries));
      

  8.   

    5楼的方法可以用,就是找到"#我爱中国china#" 后
    修改下 string test = "#我爱中国china#士大夫方式大幅士#大夫#sdf";
            Regex reg = new Regex(@"#[^#]*#|[^#]+");
            MatchCollection mc = reg.Matches(test);
            foreach (Match m in mc)
            {
                if (m.Value.ToString().Contains("#"))
                {
                    this.Label1.Text += GetUrlCode(m.Value)  ;
                }
                else
                {
                    this.Label1.Text += m.Value ;
                }自己写的方法
    string txt = "#我爱中国china#士大夫方式大幅士#大夫#sdf";        string[] txt2 = txt.Split('#');
            StringBuilder sb = new StringBuilder();
            if (txt2.Length > 2)
            {
                for (int i = 0; i < txt2.Length; i++)
                {                if (i % 2 == 1)
                    {
                        sb = sb.Append(GetUrlCode(txt2[i]));
                    }
                    else
                    {
                        sb = sb.Append(txt2[i]);
                    }            }
            }
            else 
            {
                sb = sb.Append(txt);
            }
      

  9.   

    上面得方法还是有问题,
    string txt = "#我爱中国china#士大夫方式大幅士#大夫sdf";        string[] txt2 = txt.Split('#');
            StringBuilder sb = new StringBuilder();
            if (txt2.Length > 2)
            {
                for (int i = 0; i < txt2.Length; i++)
                {                if (i % 2 == 1&&i< txt2.Length-1)
                    {
                        sb = sb.Append(GetUrlCode(txt2[i]));
                    }
                    else
                    {
                        sb = sb.Append(txt2[i]);
                    }            }
            }
            else
            {
                sb = sb.Append(txt);
            }