/// <summary> /// 获取截取内容:自定义头尾 /// </summary> /// <param name="sHtml">原文内容</param> /// <param name="strStart">开头内容</param> /// <param name="strEnd">结束内容</param> /// <param name="getStart">是否包含头内容</param> /// <param name="getEnd">是否包含尾内容</param> /// <returns></returns> private static string returnJSResult(string sHtml, string strStart, string strEnd, bool getStart, bool getEnd) { if ((strEnd == null) || (strEnd == "")) { sHtml = sHtml + "stringgggg_空尾"; strEnd = "stringgggg_空尾"; } if ((strStart == null) || (strStart == "")) { sHtml = "stringgggg_空头" + sHtml; strStart = "stringgggg_空头"; } string code = JSStr(); ScriptControlClass class2 = new ScriptControlClass(); class2.Language = "javascript"; class2.AddCode(code); object obj2 = class2.Eval(string.Format("Main(\"{0}\",\"{1}\",\"{2}\")", enReplaceStr(strStart), enReplaceStr(strEnd), enReplaceStr(sHtml))); string matchStr = deReplaceStr(obj2.ToString()); if (getStart) { matchStr = strStart + matchStr; } if (getEnd) { matchStr = matchStr + strEnd; } return(matchStr); }
private static string returnRegexStr(string strStart, string strEnd) { string code = JSStr(); ScriptControlClass class2 = new ScriptControlClass(); class2.Language = "javascript"; class2.AddCode(code); return(class2.Eval(string.Format("GetRegex(\"{0}\",\"{1}\",\"{2}\")", strStart, strEnd, "url")).ToString()); }
public static string GetJScript(string pText, string pName) { string code = CommFunc.ReadTextFileToStr((CommFunc.getDllPath() + @"\VerifyCode\Lib\") + pName + ".js"); ScriptControl control = new ScriptControlClass { UseSafeSubset = true, Language = "JScript" }; control.AddCode(code); return(control.Eval(pText).ToString()); }
public bool Eval(string expression) { Clear(); try { _result = _compiler.Eval(expression); return(true); } catch { if (_error == null) { throw; } return(false); } }
private decimal Calculate(string CalculationInfo) { try { ScriptControl sc = new ScriptControlClass(); sc.Language = "JavaScript"; string str = sc.Eval(CalculationInfo).ToString(); return(Convert.ToDecimal(str)); } catch (Exception) { return(0); } }
/// <summary> /// 按数学公式计算数据 /// </summary> /// <param name="x">单价</param> /// <param name="y">重量</param> /// <param name="z">运距</param> /// <param name="f">公式</param> /// <returns>计算结果</returns> public float compute(string x, string y, string z, string f) { if (f.IndexOf("x") > -1) { f = f.Replace("x", x); } if (f.IndexOf("y") > -1) { f = f.Replace("y", y); } if (f.IndexOf("z") > -1) { f = f.Replace("z", z); } ScriptControl sc = new ScriptControlClass(); sc.Language = "Javascript"; return(float.Parse(sc.Eval(f).ToString())); }
///需要添加引用COM:Microsoft Script Control 1.0 /// <summary> /// 执行JS代码并返回结果 /// </summary> /// <param name="sScript">JS代码</param> /// <param name="sName">JS函数名</param> /// <returns>结果</returns> private static string ExecJS(string sScript, string sName) { //string sInitUrl = "http://ipangu.baidu.com/ipangu-hint/hint/hintCustAdd_init.action"; ScriptControlClass js = new ScriptControlClass();//使用ScriptControlClass object result = null; try { js.Language = "javascript"; js.Reset(); js.Eval(sScript); //指向js脚本 object[] obj = new object[] { }; result = js.Run(sName, ref obj); //传入参数执行 } catch (Exception ex) { result = ex.Message; } return(result.ToString()); }
private void cs(object o) { int xx = 0; if (s == null) { s = new ScriptControlClass(); } /* you should be able to see consistent memory usage after 30 iterations */ while (xx < 30) { xx++; //Unsure why this is here but doesn't seem to affect the memory usage // like the ScriptControlClass object. System.Xml.XmlDocument document = new System.Xml.XmlDocument(); document.Load("ConsoleApplication6.exe.config"); s.Language = "JScript"; object res = s.Eval("1+2"); Console.WriteLine("thread {0} execution {1}", o, xx); System.Threading.Thread.Sleep(5000); } s = null; }
public string Hash(string qq, string ptwebqq) { const string url = "http://0.web.qstatic.com/webqqpic/pubapps/0/50/eqq.all.js"; //获取hash 函数代码所在JS文件 var jsContent = HttpHelper.Get(url); var index = jsContent.IndexOf("P=function(", StringComparison.Ordinal); var end = jsContent.IndexOf(",b=function(b){c.out", StringComparison.Ordinal) - 1; var hashJs = jsContent.Substring(index, end - index + 1); var js = new ScriptControlClass { Language = "javascript" };//使用ScriptControlClass js.Reset(); js.Eval(hashJs); return js.Run("P", new object[] { qq, ptwebqq }).ToString(); }
private static string returnRegexStr(string strStart, string strEnd) { string code = JSStr(); ScriptControlClass class2 = new ScriptControlClass(); class2.Language = "javascript"; class2.AddCode(code); return class2.Eval(string.Format("GetRegex(\"{0}\",\"{1}\",\"{2}\")", strStart, strEnd, "url")).ToString(); }
/// <summary> /// 获取截取内容:自定义头尾 /// </summary> /// <param name="sHtml">原文内容</param> /// <param name="strStart">开头内容</param> /// <param name="strEnd">结束内容</param> /// <param name="getStart">是否包含头内容</param> /// <param name="getEnd">是否包含尾内容</param> /// <returns></returns> private static string returnJSResult(string sHtml, string strStart, string strEnd, bool getStart, bool getEnd) { if ((strEnd == null) || (strEnd == "")) { sHtml = sHtml + "stringgggg_空尾"; strEnd = "stringgggg_空尾"; } if ((strStart == null) || (strStart == "")) { sHtml = "stringgggg_空头" + sHtml; strStart = "stringgggg_空头"; } string code = JSStr(); ScriptControlClass class2 = new ScriptControlClass(); class2.Language = "javascript"; class2.AddCode(code); object obj2 = class2.Eval(string.Format("Main(\"{0}\",\"{1}\",\"{2}\")", enReplaceStr(strStart), enReplaceStr(strEnd), enReplaceStr(sHtml))); string matchStr = deReplaceStr(obj2.ToString()); if (getStart) matchStr = strStart + matchStr; if (getEnd) matchStr = matchStr + strEnd; return matchStr; }