在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
方法一: 用Microsoft.Vsa方法
代码
string Expression = "var result:int =0;result==1?\"成功\":\"失败\"";
Microsoft.JScript.Vsa.VsaEngine ve = Microsoft.JScript.Vsa.VsaEngine.CreateEngine(); Console.WriteLine(Microsoft.JScript.Eval.JScriptEvaluate(Expression, ve));
方法二: 用Javascript中的eval方法.
代码
/// <summary>
/// 引用com组件Microsoft Script Control /// %SystemRoot%\system32\msscript.ocx /// <param name="Expression"></param> /// <returns></returns> public static string Eval(string Expression) { string strResult = null; try { MSScriptControl.ScriptControlClass jscript = new MSScriptControl.ScriptControlClass(); jscript.Language = "JScript"; strResult = jscript.Eval(Expression).ToString(); } catch (Exception ex) { Debug.Fail(ex.Message); } return strResult; }
|
请发表评论