Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: regex Replace function


Message #1 by "Jon Hilton" <jmh@s...> on Tue, 29 Jan 2002 15:25:26 -0000
This is a multi-part message in MIME format.



------=_NextPart_000_0021_01C1A8D9.2D78DDF0

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Being new to regular expressions, I find myself confused by an error

message that I'm getting whilst attempting to perform a simple

regex.replace.



I need to take a simple string such as "c:\intranet\aspnet" and delete

the "c:\intranet\" from the beginning (just leaving aspnet at the end)



The following is the code I'm attempting to use.



..........



Dim regexp as Regex =3D new Regex("c:\intranet\", 

RegexOptions.IgnoreCase)



strViewLocation =3D regexp.Replace(strBaseDir, "")



..........



The error I'm getting is...



System.ArgumentException: parsing "c:\intranet\" - Unrecognized escape

sequence \i. Parameter name: c:\intranet\



I think asp.net is interpreting the \ in the middle of the string as

being an expression of some sort, how do I get asp.net to ignore that

and just read it as a string?!



Thanks in advance for any help with this.



Jon



Jon Hilton

Web Co-ordinator

Shrewsbury Sixth Form College






Message #2 by "Denis" <dgobo@w...> on Tue, 29 Jan 2002 10:28:16 -0500
This is a multi-part message in MIME format.



------=_NextPart_000_0011_01C1A8AF.AB5A0070

Content-Type: text/plain;

	charset="us-ascii"

Content-Transfer-Encoding: 7bit



to escape a \  use \\  I don't know if this is the problem



-----Original Message-----

From: Jon Hilton [mailto:jmh@s...] 

Sent: Tuesday, January 29, 2002 10:25 AM

To: aspx_beginners

Subject: [aspx_beginners] regex Replace function





Being new to regular expressions, I find myself confused by an error

message that I'm getting whilst attempting to perform a simple

regex.replace.



I need to take a simple string such as "c:\intranet\aspnet" and delete

the "c:\intranet\" from the beginning (just leaving aspnet at the end)



The following is the code I'm attempting to use.



..........



Dim regexp as Regex = new Regex("c:\intranet\", RegexOptions.IgnoreCase)



strViewLocation = regexp.Replace(strBaseDir, "")



..........



The error I'm getting is...



System.ArgumentException: parsing "c:\intranet\" - Unrecognized escape

sequence \i. Parameter name: c:\intranet\



I think asp.net is interpreting the \ in the middle of the string as

being an expression of some sort, how do I get asp.net to ignore that

and just read it as a string?!



Thanks in advance for any help with this.



Jon



Jon Hilton

Web Co-ordinator

Shrewsbury Sixth Form College




$subst('Email.Unsub'). 








Message #3 by "Cliff Schneide" <Cliff_Schneide@n...> on Tue, 29 Jan 2002 10:56:27 -0500
One or two suggestions...

Use the replace function and put two \\ for each \ and make the c:\intranet\ a

string var and put the var in the program.



Cliff Schneide

Web Developer

Computer Aid Inc.





Message #4 by "Jon Hilton" <jmh@s...> on Tue, 29 Jan 2002 16:31:04 -0000
Thanks



The double \\ for every \ made it work!



Regards



Jon Hilton

Web Coordinator

Shrewsbury Sixth Form College

www.ssfc.ac.uk

----- Original Message -----

From: "Cliff Schneide" <Cliff_Schneide@n...>

To: "aspx_beginners" <aspx_beginners@p...>

Sent: Tuesday, January 29, 2002 3:56 PM

Subject: [aspx_beginners] Re: regex Replace function





> One or two suggestions...

> Use the replace function and put two \\ for each \ and make the

c:\intranet\ a

> string var and put the var in the program.

>

> Cliff Schneide

> Web Developer

> Computer Aid Inc.

>

>

>




$subst('Email.Unsub').

>



Message #5 by "Graham Dobson" <grahamdo@a...> on Tue, 29 Jan 2002 12:11:06 -0500
You can also use the verbatim sign as in

@"D:\\myDirectory\myfile.fil"  which forces compiler to read the string and

all characters literally.

----- Original Message -----

From: "Cliff Schneide" <Cliff_Schneide@n...>

To: "aspx_beginners" <aspx_beginners@p...>

Sent: Tuesday, January 29, 2002 10:56 AM

Subject: [aspx_beginners] Re: regex Replace function





> One or two suggestions...

> Use the replace function and put two \\ for each \ and make the

c:\intranet\ a

> string var and put the var in the program.

>

> Cliff Schneide

> Web Developer

> Computer Aid Inc.

>

>

>




$subst('Email.Unsub').

>




  Return to Index