2012-01-23 49 views
-5

我从一个网站得到了这段代码。它将unicode转换为印地文字体。它使用匹配,但我不遵循如何在其他地方定义它。它在'>'附近产生错误。Match Evaluator not working

string input = "0928;0940;0932;092E;"; 
Regex rx = new Regex(@"([0-9A-Fa-f]{4});"); 
string output = rx.Replace(input, match => ((char)Int32.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString()); 
textBox1.Text = output; 

更新

错误: '匹配' 不存在当前上下文存在。

+5

,什么是错误? – Strillo

+0

错误是:匹配在当前上下文中不存在。 – RKh

回答

1

如果您真正使用C#2.0(基于您的标记),那么在C#3.0之前不支持lambda表达式。因此,您不能使用match => ...

试试这个,而不是你的string output = ...行:

string output = rx.Replace(input, delegate(Match match) { 
     return ((char)Int32.Parse(match.Groups[1].Value, NumberStyles.HexNumber)).ToString(); 
    }); 
+0

或创建一个实际的命名方法,这将有助于可读性... –

+0

@ziesemer谢谢。它在.NET 4.0中工作。 – RKh