string str = "我是{CD小明}我爱{CQ北京}天{CC安}门";
MatchCollection collection = Regex.Matches(str, @"\{([^\{^\}]*)\}");
foreach (Match match in collection)
{
    Console.WriteLine(match.Groups[1].Value);
}

解决方案 »

  1.   


    string s = " 我是{CD小明}我爱{CQ北京}天{CC安}门";
    string ss = s.Replace("{", "").Replace("}", "");
    MessageBox.Show(ss);
      

  2.   

    使用正则是比较理想的解决方法,否则使用indexof只能一次次的取
      

  3.   

    int i = s.IndexOf("{");
    int j = s.IndexOf("}");
    你这个只是取第一个{CD小明}的{}的位置,所以取出来是只能是第一个,要3个文本框的内容一个一个取,但你计算也不对,
     int i = s.IndexOf("{");
              int j = s.IndexOf("}");
              string s1 = s.Substring(0,i);
              string s2 = s.Substring(i+1, j - i-1);
              MessageBox.Show(s1 + s2);
    //我是CD小明
    不用这么复杂,{}直接用 Replace替换就可,字符串的Replace替换,你百度一下就知道怎么应用了。
      

  4.   

    你可以这样写var result = s.Split('{').Where((x, i) => i > 0).Select(x => x.Split('}').First()).ToArray();
    var ss= String.Join(",", result);