110,536
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
}
}
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";
string str1 = evalstr(str2);
Console.WriteLine(str1);
}
static string evalstr(string s)
{
return Regex.Replace(s, @"\\(.)", "$1");
}
}
}