473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Add markup code to specific words in a text


Hi

Wonder how the should use the Regex members to add markup code to words
in a text.
Code:
--------------------

string words1 = "dog|cat|pig|horse|hippo";
string text1 = "hadsf das adh f dog adhsf yagds uyaudfyas gdf pig afsd. agfg afd gasd fgasd g dog. aygs fag fiusadf gi cat hasd horse, asdf pig. asdygf is dfisiau dfgisadf ias ufg dog.";

text1 = Regex.Replace(text1, somepattern, somereplace, someoptions);

Output:
hadsf das adh f [span class="blue"]dog[/span] adhsf yagds uyaudfyas gdf [span class="blue"]pig[/span] afsd. agfg afd gasd fgasd g [span class="blue"]dog[/span]. aygs fag fiusadf gi [span class="blue"]cat[/span] hasd [span class="blue"]horse[/span], asdf [span class="blue"]pig[/span]. asdygf is dfisiau dfgisadf ias ufg [span class="blue"]dog[/span].

--------------------
Cheers / Toska

--
Toska
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 19 '05 #1
1 1258
Toska wrote:
Wonder how the should use the Regex members to add markup code to words
in a text.

To highlight words matched by the words1 expression found in text1 in
your example, you can use the following code (C#):
string words1 = "dog|cat|pig|horse|hippo";
string text1 = "hadsf das adh f dog adhsf yagds uyaudfyas gdf pig afsd.
agfg afd gasd fgasd g dog. aygs fag fiusadf gi cat ";

Regex r=new Regex(words1);
string result=r.Replace(text1,"<em>$&</em>");

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #2

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

Similar topics

7
by: Jacek Generowicz | last post by:
:::Title::: A simple text markup utility :::/Title::: :::Section Introduction ::: I'm looking for something to help developers wirte documentation for bits of software they are writing. The...
4
by: chris | last post by:
hi, i am looking for a way to structure the text in XML comments to produce a XHTML doc format for the XMLs (in this case XSLT). so is was thinking about using a wiki like text format. e.g....
30
by: Reinhold Birkenfeld | last post by:
Hello, I know that there are different YAML engines for Python out there (Syck, PyYaml, more?). Which one do you use, and why? For those of you who don't know what YAML is: visit...
43
by: David Trimboli | last post by:
In a text, I might want to include a foreign language term. In print, this is typically shown with italics. For instance (asterisks represent italics): 'I thought it was only a kind of *cram,*...
47
by: Andy Dingley | last post by:
Assume an English language page, linking to a foreign history resource that's only available in a foreign language. Any suggestions on appropriate "best practice" markup, particularly regarding the...
7
by: Lachlan Hunt | last post by:
Hi, I have recently downloaded and experemented with IBM HPR 3.0, and Opera 8 with text-to-speech, and have come to realise some fairly annoying issues regarding punctuation marks. I've found,...
8
by: Steve Jorgensen | last post by:
Hi folks, I'm posting this message because it's an issue I come up against relatively often, but I can't find any writings on the subject, and I haven't been able to figure out even what key...
3
by: Michal A. Valasek | last post by:
Hello, I want to transform text with HTML markup to plain text. Is there some simple way how to do it? I can surely write my own function, which would simply strip everything with < and >....
16
by: Andreas Prilop | last post by:
I have three test pages that are marked as Italian, Spanish, Portuguese, resp. by Content-Language: it <html lang="it"> <body lang="it"> and the same for "es" and "pt". Yahoo regards all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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...

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.