日期:2014-05-17 浏览次数:20917 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str2 = @"abc\'123\\\""1/0";
string str1 = evalstr(str2);
Console.WriteLine(str1);
}
static string evalstr(string s)
{
try
{
MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
sc.Language = "javascript";
string s1 = Regex.Replace(s, @"(?<!\\)((\\\\)*)\""", @"$1\""");
sc.AddCode("function foo() { return \"" + s1 + "\"; }");
return sc.Run("foo", new object[] { }).ToString();
}
catch (Exception ex)
{
return s; //ex.Message;
}
}
&nbs