.NETGURU
Using Replace - Not working right
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.


Dot Net Guru Moore
I am using the Regex.Replace function and it is not working properly.

Here is the code.

n = dr["name"].ToString();
msg = Regex.Replace(msg, "[[name]]", n);

msg is a HTML email that will be sent. I am trying to replace the "[[name]]" with the name from the data base but these are the results:

"Your name is going to be inserted right here: [[namDot Net Guru] . .............."

It replaced the "e]" but no the rest of the name tag. Do you have any ideas?

Thanks
Dot Net Guru
Reply to this message...
 
    
Wayne King
Have you considered just using the String.Replace() method? From the =
description of the problem, it sounds like you may not need to use =
regular expressions.
    msg =3D msg.Replace("[[name]]", n);

You're not seeing the results you expect because your pattern contains =
special regex characters. The sequence [[name] means, 'match one =
character that is either a left square bracket, an n, an a, an m, or an =
e.' If you really want to use a regex, this should work for you:
    msg =3D Regex.Replace(msg, "\[\[name]]", n);

-----Original Message-----
From: Dot Net Guru Moore [mailto:Click here to reveal e-mail address]
Sent: Thursday, May 16, 2002 2:36 PM
To: aspngregexp
Subject: [aspngregexp] Using Replace - Not working right

-- Moved from [aspngfreeforall] to [aspngregexp] by devin rader =
<Click here to reveal e-mail address> --

I am using the Regex.Replace function and it is not working =
properly.=3D20
=3D20
Here is the code.=3D20
=3D20
n =3D3D dr["name"].ToString();
msg =3D3D Regex.Replace(msg, "[[name]]", n);
=3D20
msg is a HTML email that will be sent. I am trying to replace the =3D
"[[name]]" with the name from the data base but these are the results:
=3D20
"Your name is going to be inserted right here: [[namDot Net Guru] . =3D
.............."
=3D20
It replaced the "e]" but no the rest of the name tag. Do you have any =
=3D
ideas?
=3D20
Thanks
Dot Net Guru

Reply to this message...
 
 
System.String
System.Text.RegularExpressions.Regex




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification