473,657 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expressions - Replace

Hi

I want to replace a word using Regular Expression for that i am using below
code

strResult = System.Text.Reg ularExpressions .Regex.Replace( strInput,
txtSearch.Text. ToString().Trim (), "<b>" + txtSearch.Text. ToString().Trim () +
"</b>", System.Text.Reg ularExpressions .RegexOptions.I gnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant
Nov 19 '05 #1
4 1519
Hemant wrote:
Hi

I want to replace a word using Regular Expression for that i am using
below code

strResult = System.Text.Reg ularExpressions .Regex.Replace( strInput,
txtSearch.Text. ToString().Trim (), "<b>" +
txtSearch.Text. ToString().Trim () + "</b>",
System.Text.Reg ularExpressions .RegexOptions.I gnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant


I think you want the overload of the Replace method that uses
a MatchEvaluator as second parameter.

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

Hans Kesting
Nov 19 '05 #2
Thank you Hans for quick reply.

According to your post
This will make starting first characters capital... but i dont want that, I
want to retain the original state of the word. I am using this for site
search using Index server.

For more help,

Suppose user searches for keyword = Test
and suppose we found this keyword in the search result. The contents of the
file is <This is test>.

so if i apply your suggested post the result will be 'This Is Test' which is
wrong.
actaully what i want that It should show the result as
This is <b> test </b>
here the word 'test' should be bold and nothing else should change.

Thank you
Regards
Hemant

"Hemant" wrote:
Hi

I want to replace a word using Regular Expression for that i am using below
code

strResult = System.Text.Reg ularExpressions .Regex.Replace( strInput,
txtSearch.Text. ToString().Trim (), "<b>" + txtSearch.Text. ToString().Trim () +
"</b>", System.Text.Reg ularExpressions .RegexOptions.I gnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant

Nov 19 '05 #3
Hemant wrote:
Thank you Hans for quick reply.

According to your post
This will make starting first characters capital... but i dont want
that, I want to retain the original state of the word. I am using
this for site search using Index server.

No, that "first capital" is just an example to show that you have access to
the exact text found. What *you* should do is just take the text found and
surround it with <b> </b> tags. That way you preserve the casing.
For more help,

Suppose user searches for keyword = Test
and suppose we found this keyword in the search result. The contents
of the file is <This is test>.

so if i apply your suggested post the result will be 'This Is Test'
which is wrong.
actaully what i want that It should show the result as
This is <b> test </b>
here the word 'test' should be bold and nothing else should change.

Thank you
Regards
Hemant

"Hemant" wrote:
Hi

I want to replace a word using Regular Expression for that i am
using below code

strResult = System.Text.Reg ularExpressions .Regex.Replace( strInput,
txtSearch.Text. ToString().Trim (), "<b>" +
txtSearch.Text. ToString().Trim () + "</b>",
System.Text.Reg ularExpressions .RegexOptions.I gnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant

Nov 19 '05 #4
Thank you Hans

"Hans Kesting" wrote:
Hemant wrote:
Thank you Hans for quick reply.

According to your post
This will make starting first characters capital... but i dont want
that, I want to retain the original state of the word. I am using
this for site search using Index server.


No, that "first capital" is just an example to show that you have access to
the exact text found. What *you* should do is just take the text found and
surround it with <b> </b> tags. That way you preserve the casing.
For more help,

Suppose user searches for keyword = Test
and suppose we found this keyword in the search result. The contents
of the file is <This is test>.

so if i apply your suggested post the result will be 'This Is Test'
which is wrong.
actaully what i want that It should show the result as
This is <b> test </b>
here the word 'test' should be bold and nothing else should change.

Thank you
Regards
Hemant

"Hemant" wrote:
Hi

I want to replace a word using Regular Expression for that i am
using below code

strResult = System.Text.Reg ularExpressions .Regex.Replace( strInput,
txtSearch.Text. ToString().Trim (), "<b>" +
txtSearch.Text. ToString().Trim () + "</b>",
System.Text.Reg ularExpressions .RegexOptions.I gnoreCase);

strInput = "This is a Test."
txtSearch.Text = "test"
strResult ="this is a <b>test</b>."

I want capital 'T' <test> in strResult what should i do?

Thanks in advance
Regards
Hemant


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4167
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
1
2018
by: Graham Mattingley | last post by:
Hi, I have an issue where by when I use XMLHTTP to get data from another web site, all of the '£' symbols become '?'. I have try for hours to stop this happening but have been unsuccessful so far. The numbers I have for example should be £9.57 and become ?9.57. I am by no means an ASP expert and I have found some of the suggestion a bit difficult to understand, somebody suggested "ADODB.Stream" but I could not make this work..
3
3209
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is that this will one or more occurrences to replace all the white space between with a comma. This search ElseIf InStr(1, indivline, "$") Then insert a replace statement that uses the regular expression to find and replace all the white space...
7
371
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist - Album- i have try this syntax but it failed
4
4825
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional way mean to secrife lots of time in asp.net. can any one give me such a expression in which i pass a data string and search word string and replace word string? if so plz help me out. i'm in badly need.
7
3818
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
9
3353
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use an app call The Regulator, which makes it pretty easy to build and test regular expressions. As a warning, I'm real weak with regular expressions. Let's say my regular expression is:
0
1947
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use of string manipulation where they seek through the string back and forth doing replacements to substitute in the needed HTML code. I am convinced that this can be done with a few regular expressions. Unfortunately my knowledge of regular...
1
3387
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though: --------------------------------- var match = myStringVar.match("^" + iName + "=,($|&)");
2
1558
by: Stimp | last post by:
Hi all, I'm having trouble trying to figure out the best approach to this problem and I believe regular expressions are the way to go. Basically I have created a large string of XHTML using a WYSIWYG editor, so the string is like "<p>dfdsfjhds <img src='temp.jpg' /> dsfdsfsd</p><p>dfsdfsdfsd</p... " What I want to do is the following...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8502
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.