By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

RegEx not found in System.Text.RegularExpressions???

P: n/a
Hi All,

I tried using RegEx, but the compiler barfed with "The type of namespace
'RegEx' could not be found.

Prior to this, I had the same problem with MatchCollection, but discovered
it's in the namespace "System.Text.RegularExpressions;" and that namespace
is, in turn, defined in the namespace "System", according to MSDN at
http://msdn2.microsoft.com/en-us/lib...us,VS.80).aspx. So
adding "using System.Text.RegularExpressions" was sufficient to resolve this
issue. I didn't need to add any additional reference to my project.

MSDN says at the same webpage that RegEx is in the
"System.Text.RegularExpressions" namespace, just like MathCollection. So
why do I have a problem with it?

The program is listed below.

**More generally**, what's the best way to learn for any class (1) what
namespace it's defined in; and (2) what assembly implements that namespace
and its classes?

Thanks in advance,
Richard

======= MainClass.cs ==========
using System;
using System.Text.RegularExpressions; // MatchCollection

namespace FileBrowser
{
class MainClass
{
[STAThread]
static void Main(string[] args)
{
string sText = "When one + two = twenty";
string sPat = "(/\\w*w\\w*/)*";
MatchCollection mc;
mc = RegEx.Matches (sText, sPat);
Console.WriteLine("Count = (0)", mc.Count);
}
}
}
Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Thu, 3 Nov 2005 21:19:19 -0500, "Richard Lionheart"
<No***@Nowhere.net> wrote:
mc = RegEx.Matches (sText, sPat);


C# is case sensitive so that should be 'Regex', not 'RegEx'.

If you are using VS.Net, consider using ctrl+space to bring up valid
types, etc.

--
Marcus Andrén

Nov 17 '05 #2

P: n/a
On Thu, 3 Nov 2005 21:19:19 -0500, "Richard Lionheart"
<No***@Nowhere.net> wrote:

**More generally**, what's the best way to learn for any class (1) what
namespace it's defined in; and (2) what assembly implements that namespace
and its classes?


I forgot to answer this question. In my opinion, the only way to learn
it is by using it. The more you use something the easier it is to
remember.

1) The following link contains a short description of the contents of
each namespace. As you use different classes you will begin to see the
pattern and know where to look for them.

http://msdn.microsoft.com/library/de...pref_start.asp

2) A lot of the basic functionality is in the mscorlib that is used
for all c# programs. If you need another assembly it is usually
because you are trying to interact with an external system that has a
specific purpose. For example, System.Windows.Forms.dll and
System.Drawing.dll for windows programming or System.Web for web
programming. System.Data and its deratives for database programming.

The big exception is probably System.dll that contains the stuff that
they didn't want to put in the mscorlib, but still are quite generic
or maybe not big enough to occupy their own assembly. Regular
expressions are one such thing.

In my experience, most programs will make use of System.dll, so
including it in all projects is also a valid option.

--
Marcus Andrén
Nov 17 '05 #3

P: n/a
If you are using VisualStudio IDE, I found the ClassBrowser to be of great
initial help in figuring out where things were, especially the "find"
function if you only remember part of the class name.

Class Browser can be found in the IDE by "View->Class Browser".
hth,
Scott

"Richard Lionheart" <No***@Nowhere.net> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I tried using RegEx, but the compiler barfed with "The type of namespace
'RegEx' could not be found.

Prior to this, I had the same problem with MatchCollection, but
discovered it's in the namespace "System.Text.RegularExpressions;" and
that namespace is, in turn, defined in the namespace "System", according
to MSDN at
http://msdn2.microsoft.com/en-us/lib...us,VS.80).aspx. So
adding "using System.Text.RegularExpressions" was sufficient to resolve
this issue. I didn't need to add any additional reference to my project.

MSDN says at the same webpage that RegEx is in the
"System.Text.RegularExpressions" namespace, just like MathCollection. So
why do I have a problem with it?

The program is listed below.

**More generally**, what's the best way to learn for any class (1) what
namespace it's defined in; and (2) what assembly implements that namespace
and its classes?

Thanks in advance,
Richard

======= MainClass.cs ==========
using System;
using System.Text.RegularExpressions; // MatchCollection

namespace FileBrowser
{
class MainClass
{
[STAThread]
static void Main(string[] args)
{
string sText = "When one + two = twenty";
string sPat = "(/\\w*w\\w*/)*";
MatchCollection mc;
mc = RegEx.Matches (sText, sPat);
Console.WriteLine("Count = (0)", mc.Count);
}
}
}

Nov 17 '05 #4

P: n/a
Hi Marcus,
C# is case sensitive so that should be 'Regex', not 'RegEx'. I knew C#, like C and C==, is case sensitive. But I didn't notice it when I
look at MSDN and then my good. It's embarassing! Thanks for pointing my
glaring error.
If you are using VS.Net, consider using ctrl+space to bring up valid
types, etc.


I am using VS.NET and have been using ctl-space, but never on a partial
initial class name, only after the period following it. But after receiving
your comment I tried out Intellisense after typing just "Re" and it would
have prevented my error! So thanks for taking the extra time to offer that
advice in addition to your specific correction. It's a big help.

Regards,
Richard
Nov 17 '05 #5

P: n/a
Hi Marcus,

Thanks for picking up on my other question.
1) The following link contains a short description of the contents of
each namespace. As you use different classes you will begin to see the
pattern and know where to look for them.

http://msdn.microsoft.com/library/de...pref_start.asp
I had looked at this page in VS.NET/Help:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/cpref_start.htm

It, of course, answers the question, "what are the namespaces/classes
defined in the high-level namespaces defining the FCL". But, as I posted, I
want the inverse question answered: "what namespace defines namespace xxx?
and is that namespace and its classes defined by an assembly or a
higher-level namespace which *is* defined by an assembly. And are the names
of the assembly and it's companion assembly."

I pretty sure I used some utility that answers the latter question, but I
can't rember what it was. But now that I'm getting serious about using .NET
for developing Web apps, I've got to find such tools.
2) A lot of the basic functionality is in the mscorlib that is used
for all c# programs. If you need another assembly it is usually
because you are trying to interact with an external system that has a
specific purpose. For example, System.Windows.Forms.dll and
System.Drawing.dll for windows programming or System.Web for web
programming. System.Data and its deratives for database programming.

The big exception is probably System.dll that contains the stuff that
they didn't want to put in the mscorlib, but still are quite generic
or maybe not big enough to occupy their own assembly. Regular
expressions are one such thing.

In my experience, most programs will make use of System.dll, so
including it in all projects is also a valid option.


Thanks for this additional perspective.

Best wishes,
Richard
Nov 17 '05 #6

P: n/a
Hi Scott,

Thanks for responding.
If you are using VisualStudio IDE, I found the ClassBrowser to be of great
initial help in figuring out where things were, especially the "find"
function if you only remember part of the class name.
That's exactly what I'm looking for.
Class Browser can be found in the IDE by "View->Class Browser".

When I receive your email, I looked for a "Class Brower" item in the View
menu but didn't see it. As I was preparing this response, I was going to
tell you this and mention that I remember using Object Browser in VS 6.0 and
express my disappointment that MS seems to have dropped it in VS.NET.

But before I did that, I thought I better take a second look. Happily, I
found View | Other Windows | Object Browser. (I'm running VS.NET Pro 2002.)
One more little detail: Object Browser returns nothing if no project is
open, and maybe it has to be one of a group of selected projects.

Bottom line: Thank you very much for getting me to look in the View menu.
I'm a happy camper now.

Best wishes,
Richard
Nov 17 '05 #7

P: n/a
On Sat, 5 Nov 2005 01:38:36 -0500, "Richard Lionheart"
<No***@Nowhere.net> wrote:
It, of course, answers the question, "what are the namespaces/classes
defined in the high-level namespaces defining the FCL". But, as I posted, I
want the inverse question answered: "what namespace defines namespace xxx?
and is that namespace and its classes defined by an assembly or a
higher-level namespace which *is* defined by an assembly. And are the names
of the assembly and it's companion assembly."


Namespaces don't have levels. System is completly seperated from
System.Text which is completely different from
System.Text.RegularExpressions.

Namespaces are simply a way to hide the complete type names. Regex
isn't the real type name. System.Text.RegularExpressions.Regex is.

Just because two types have the same namespace doesn't mean they have
anything to do with each other. They can be in two different
assemblies and not care at all.

Namespaces have two purposes, the first is to give some sense of order
and the second is to prevent name collisions:

System.Web.UI.Control
vs
System.Windows.Forms.Control

Assemblies have one purpose and that is to group a bunch of types into
a single file.

--
Marcus Andrén
Nov 17 '05 #8

P: n/a
Hi Marcus,

Thanks for the additional thoughts about my question.
It, of course, answers the question, "what are the namespaces/classes
defined in the high-level namespaces defining the FCL". [snip]
Namespaces don't have levels. System is completly seperated from
System.Text which is completely different from
System.Text.RegularExpressions.
That seems weird to me. If System.Text isn't subordinate to System, why
not simpl name it "Text"?
Namespaces are simply a way to hide the complete type names. Regex
isn't the real type name. System.Text.RegularExpressions.Regex is.
I understand that System.Text.RegularExpressions is the namespace in which
Regex and other classes are defined. But again it looks to me like VS.NET,
when compiling a C# program, picks up some file that includes statements
like:

namespace System
{
class AccessViolationException { [snip] }
class ActivationContext { [snip] }
[snip]
namespace CodeDom { [snip] }
namespace Collections{ [snip] }
namespace ComponentModel { [snip] }
[snip]
}

I searched %SYSTEMDRIVE%\Program Files\Microsoft.NET for files containing
such definitions to no avail, so I guess I'm all wet.
Just because two types have the same namespace doesn't mean they have
anything to do with each other. They can be in two different
assemblies and not care at all.
I recognize that, but when I concoct some some notion about handling, say,
strings some pareticular way, I'd like to see all the namespaces that are
involved with strings, one way or the other. Then I'd like to poke through
those namespaces to find classes and their methods so that if some relevant
functionality exists, I can employ it rather than indavertantly "reinvent
the wheel."

Happily, that's what Object Browser seems to do, I think. I haven't used it
yet under VS.NET, but I did use it years ago with VC++ in VS 6.0.
Namespaces have two purposes, the first is to give some sense of order
and the second is to prevent name collisions:
Understood.
Assemblies have one purpose and that is to group a bunch of types into
a single file.


That's a point of view I'm glad to learn. I still haven't poke through any
of them yet.

Again, thanks for taking the time to educate me. The burden of learning
new technologies when, to paraphrase Blanch duBois in "Streetcar Named
Desire", one has the benefit of kindness of strangers :-)

Best wishes,
Richard
Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.