比如说有这样一个字符串,string aa="ni hao wo {fslj} shi duan xiao {fsfd} ming";
把这个字符串中的{}内的内容提取出来返回数组什么的就可以了,其他不要

解决方案 »

  1.   

    using System;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        string aa = "ni hao wo {fslj} shi duan xiao {fsfd} ming"; 
        foreach (Match m in Regex.Matches(aa, @"\{.*?\}"))
        {
          Console.WriteLine(m.Value);
        }
      }
    }
      

  2.   


                string aa = "ni hao wo {fslj} shi duan xiao {fsfd} ming";
                List<string> list = new List<string>();
                foreach (Match m in Regex.Matches(aa, "\\{(?<text>\\w*)\\}"))
                {
                    list.Add(m.Groups["text"].Value);
                }
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        string aa = "ni hao wo {fslj} shi duan xiao {fsfd} ming";
        string[] bb = GetValue(aa);
        foreach (string s in bb)
        {
          Console.WriteLine(s);
        }
      }
       
      // 如果获取的内容不包括 {}
      static string[] GetValue(string s)
      {
        List<string> l = new List<string>();
        foreach (Match m in Regex.Matches(s, @"(?<=\{).*?(?=\})"))
        {
          l.Add(m.Value);
        }
        return l.ToArray();
      }
    }
      

  4.   

          string aa = "ni hao wo {fslj} shi duan xiao {fsfd} ming";
                List<string> list = new List<string>();
                foreach (Match m in Regex.Matches(aa, "\\{(?<text>\\w*)\\}"))
                {
                    list.Add(m.Groups["text"].Value);
                }