匹配评估器不起作用

时间:2012-01-23 10:38:46

标签: c# c#-2.0

我从网站上获取此代码。它将unicode转换为印地语字体。它使用匹配,但我不遵循如何在别处定义它。它会在'>'附近生成错误。

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;

更新

错误:当前上下文中不存在“匹配”。

1 个答案:

答案 0 :(得分: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();
    });
相关问题