我有以下代码
string s = "add(2,3);";
var matchess = Regex.Matches(s, @"\(\s*(?<num>\d+)\s*(\,\s*(?<num>\d+)\s*)*\)");
var results = matchess.Cast<Match>()
.SelectMany(m => m.Groups["num"].Captures.Cast<Capture>())
.Select(c => c.Value).ToArray();
上面的代码检测到超过 2 个 functionname(number,number) 的输入,并将结果存储在 arraylist 中以便能够访问。
有没有办法改变方程,使其也接受以下内容并相应地打印结果?
示例 1
string s = "add(2.2,3.3);";
结果 1
results[0] = 2.2
results[1] = 3.3
示例 2
string s = "add(2.4,3.5,6.7);";
结果 2
results[0] = 2.4
results[1] = 3.5
results[2] = 6.7
示例 3
string s = "test("this is a test","just an example");";
结果 3
results[0] = "this is a test"
results[1] = "just an example"
示例 4
string s = "test("this is a test","just an example","testing");";
结果 4
results[0] = "this is a test"
results[1] = "just an example"
results[2] = "testing"
基本上我需要的是函数名(十进制,十进制)和函数名(字符串,字符串)的2个以上输入并将结果存储在数组列表中以访问它们。
请指教。谢谢