473,480 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
8 7782
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2776
by: Ian Payne | last post by:
Documentation says it does: Quickwatch lists it (but <cannot view indexed property> as expected) So how come the compiler throws an error? I can of course work round it (in C#) with myMatches,...
6
6064
by: hplloyd | last post by:
I am using some code off the web that requires a string builder in a script within a web page. In order to get the script to work I need to include the relevant library in the references section...
2
1262
by: Juan | last post by:
Hi, I´m using System.Text.RegularExpressions, I want to find any acurrence of the char & or % or | Ehat is the correct sintax for the Match method? This is what I´m usinf but is not working:...
2
6607
by: Doug | last post by:
I'm a little confused by this functionality. It doesn't seem to be behaving like it should. I am using the following regular expression to validate email addresses:...
1
4850
by: Mark Miller | last post by:
I just recently started getting the above error on a page I am posting MULTIPART/FORM-DATA. We have SoftArtisans FileUp component and Filter installed on the server in question and up until a day...
0
1314
by: Neo The One | last post by:
I find some of the Regex classes are quite helpful for my learning. For example: System.Web.RegularExpressions.SimpleDirectiveRege...
2
2539
by: chris fink | last post by:
Using regular expression testers such as Expresso or Dan Appleman's tester, I have a regular expression that tests fine and is returning matches. However, when the same regex is run through code,...
0
983
by: Vikram | last post by:
I am using regex class in codebehind to validate some control's text. But for checking , postback is done.I want to avoid postback and check the same exprseeion using regularexpressionvalidator. I...
1
3498
by: Sal Sal | last post by:
I am using System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, options) in c# to replace the input string. The pattern I am using may have one or more * or . or any other...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.