日期:2014-05-17 浏览次数:20831 次
string str = "(mc380a*100.2+mc380b*2)/3600/mc380b12+mc380ac*4.9";
Dictionary<string, string> dic = new Dictionary<string, string>
{
{"mc380b12","c.mc380b12"},{"mc380b","b.mc380b"},{"mc380ac","a2.mc380ac"},{"mc380a","a1.mc380a"}
};
var chars = new char[] { '*', '/', '+', '-', '(', ')' };
List<string> list = new List<string>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
if (chars.Contains(str[i]))
{
if (sb.Length > 0)
{
list.Add(sb.ToString());
sb = new StringBuilder ();
}
list.Add(str[i].ToString());
}
else
{
sb.Append(str[i].ToString());
}
}
if (sb.Length > 0)
{
&nb