110,539
社区成员
发帖
与我相关
我的任务
分享
Dictionary<string, string> str = new Dictionary<string, string>();
str.Add("a1", KryptonTextBox1.Text);
str.Add("a2", KryptonTextBox2.Text);
str.Add("a3", KryptonTextBox3.Text);
try
{
string temp = textABC.Text;
foreach (KeyValuePair<string, string> kv in str)
{
temp = Regex.Replace(temp, string.Format("^{0}|{0}$|(?<=[-+ (*/]){0}(?=[-+ )*/])", kv.Value), kv.Key);
}
Expression ep = new Expression(temp);
//Expression ep = new Expression(textABC.Text.Replace(str["a1"], "a1").Replace(str["a2"], "a2").Replace(str["a3"], "a3"));
ep.Parameters["a1"] = Convert.ToDouble(textA.Text);
ep.Parameters["a2"] = Convert.ToDouble(textB.Text);
ep.Parameters["a3"] = Convert.ToDouble(textC.Text);
labResult.Text = ep.Evaluate().ToString();
}
catch (Exception ex)
{
labResult.Text = ex.Message;
}
^{0}(?=[-+ */])|(?<=[-+ ,(*/]){0}(?=[-+ ,)*/])|(?<=[-+ */]){0}$
留个记号“^{0}(?=[-+ */])|(?<=[-+ (*/]){0}(?=[-+ )*/])|(?<=[-+ */]){0}$”
正则写成这样了 谁来挑错或接分