Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Variables in regular expressions problem

Posted on 2004-10-25
5
Medium Priority
?
278 Views
Last Modified: 2010-04-15
Hi

Can anyone tell me where I'm going wrong here.
string HighlightWord, Word1;

If I run the code below it works OK
HighlightWord = Regex.Replace(HighlightWord, "harry", "<strong>harry</strong>", RegexOptions.IgnoreCase);

But when I try and change harry to a variable it will not work, can anyone tell me what I need to change

HighlightWord = Regex.Replace(HighlightWord, "Word1", "<strong>Word1</strong>", RegexOptions.IgnoreCase);

Regards
Caz
0
Comment
Question by:BeginningWebDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Expert Comment

by:AaronReams
ID: 12406156
is this what you're trying to do?

string Word1 = "Word1";
HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>Word1</strong>", RegexOptions.IgnoreCase);
0
 
LVL 6

Expert Comment

by:Chester_M_Ragel
ID: 12407213
Its strange... Does HighlightWord string has "Word1"? If it has, surely it must get replaced by "<strong>Word1</strong>".
0
 
LVL 7

Accepted Solution

by:
sukumar_diya earned 2000 total points
ID: 12407620
Hi,
Hope u r trying this....

string HighlightWord="Harry Test test harry";
string Word1 = "Harry";
HighlightWord = Regex.Replace(HighlightWord, Word1, "<strong>" + Word1 + "</strong>", RegexOptions.IgnoreCase);

Check with this.....

Sukumar
0
 
LVL 6

Expert Comment

by:etmendz
ID: 12407962
BeginningWebDesign,

There is something wrong with your question. Wanna fix your question, rephrase it or whatever,  so we'll understand better?

:-)
0
 

Author Comment

by:BeginningWebDesign
ID: 12408116
Thanks sukumar_diya

That fixed that problem, and has caused another problem. As I only asked how to highlight a variable which you answered, I have opened another question with the new problem.

Caz
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question