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); } } }
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); }
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(); } }
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); }
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);
}
}
}
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);
}
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();
}
}
List<string> list = new List<string>();
foreach (Match m in Regex.Matches(aa, "\\{(?<text>\\w*)\\}"))
{
list.Add(m.Groups["text"].Value);
}