正则表达式的命名空间不起作用 [英] Namespace of Regex won't work

查看:45
本文介绍了正则表达式的命名空间不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在翻新一些曾经在.NET Framework 3.5上工作的旧代码,以使其使用C#在.NET Framework 4上工作.

Im refurbishing some old code that used to work on .NET Framework 3.5 to make it work on .NET Framework 4 using C#.

以下Regex以前可以在3.5版上正常工作,但由于某些奇怪的原因而不再起作用.

The following Regex used to work fine with version 3.5 but doesn't work anymore for some strange reason.

public static readonly Regex ChatColorRegex = new Regex("\\|c[A-Za-z0-9]{6,8}"),
                                 ChatLinkRegex = new Regex("\\|H.*?\\|h");

我已在文件顶部添加了"using System.Text.RegularExpressions",但出现了以下错误:名称空间System.Text中不存在类型或名称空间RegularExpressions.

I have added the 'using System.Text.RegularExpressions' at the top of my file, but the following error rises: 'The type or namespace RegularExpressions does not exist in the namespace System.Text.

我已经在Google上进行了搜索,并了解到您必须在Visual Studio中添加对System.Text.RegularExpressions的引用.但是,当我这样做的时候,我在可以添加的引用列表中找不到System.Text.RegularExpressions.

I've googled about that and read that you have to add a Reference to System.Text.RegularExpressions in Visual Studio. However, when i did, i couldn't find System.Text.RegularExpressions in the list of References i could add.

我正在使用Visual Studio 2012.

I'm using Visual Studio 2012.

谁能告诉我我做错了什么,还是忘记阅读了?

Could anyone tell me what im doing wrong, or forget to read?

推荐答案

Regex类仍位于System.Text.RegularExpression命名空间中.该类在系统程序集中.

The Regex class is still in the System.Text.RegularExpression namespace. The class is in the System assembly.

如果在解决方案资源管理器中检查项目引用,则应该看到对系统程序集的引用.检查该引用的属性,以查看用于系统程序集引用的.NET Framework版本.它应该与您在项目属性(应用程序"选项卡)中为目标框架"选择的.NET Framework版本相匹配.

If you check your project references in Solution Explorer, you should see a reference to the System assembly. Check the properties of that reference to see what .NET Framework version is being used for the System assembly reference. It should match the .NET Framework version you selected for the "Target framework" in the project properties (Application tab).

Regex类位于System.Text.RegularExpressions命名空间中,而不位于System.Text中.

这篇关于正则表达式的命名空间不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆