use js script in c
添加引用-com-Microsoft Script Control 1.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSScriptControl;//重要
namespace baseTransfrom
{
class Program
{
static string ExecuteScript(string sExpression, string sCode)//后一个参数是写脚本里的函数,一般为空。
{
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
scriptControl.UseSafeSubset = true;
scriptControl.Language = "JScript";
scriptControl.AddCode(sCode);
try
{
string str = scriptControl.Eval(sExpression).ToString();
return str;
}
catch (Exception ex)
{
string str = ex.Message;
}
return null;
}
}
}