GetBoldWords()

A

Aaron

This example that Mun give me works fine if theres only one set of
bold tags <b>ddf</b> but it would fail if there are more than one
input = "<b>ddf</b><b>dddfs</b>"
output = "ddf</b><b>dddfs"

is there a way to save each word in bold into an array?

Thanks,
aaron
-------------------
Here's my original post
I need a function in c# that finds and outputs word in bold.


string input = "<b>Hello my name</b> is John"

public string GetBoldWords()
{
//the function
return s // s = "Hello my name"
}

thanks
-------------------------------------------------
You could use the regular expression - <b>(.*)</b>.

public string GetBoldWords(string somestring)
{
string foundMatch = string.Empty;
Regex RegExObj= new Regex("<b>(.*)</b>", RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Match MatchObj =
RegExObj.Match(somestring);
if (MatchObj.Success) foundMatch = MatchObj.Groups[1].Value;
return foundMatch;
}


Hope this helps,

Mun
 
P

Paul Hetherington

Just a shot in the dark but try something like this.
Embed the string you want to parse into an xml document(i.e. <parsethis>
..... </parsethis>)
Then use the System.XML namespace to help you parse it as an xml document
looking for the <b> tags.
You can use XMLTextReader or XMLDocument for this.

Hope this helps
Cheers,
Paul
Aaron said:
This example that Mun give me works fine if theres only one set of
bold tags <b>ddf</b> but it would fail if there are more than one
input = "<b>ddf</b><b>dddfs</b>"
output = "ddf</b><b>dddfs"

is there a way to save each word in bold into an array?

Thanks,
aaron
-------------------
Here's my original post
I need a function in c# that finds and outputs word in bold.


string input = "<b>Hello my name</b> is John"

public string GetBoldWords()
{
//the function
return s // s = "Hello my name"
}

thanks
-------------------------------------------------
You could use the regular expression - <b>(.*)</b>.

public string GetBoldWords(string somestring)
{
string foundMatch = string.Empty;
Regex RegExObj= new Regex("<b>(.*)</b>", RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Match MatchObj =
RegExObj.Match(somestring);
if (MatchObj.Success) foundMatch = MatchObj.Groups[1].Value;
return foundMatch;
}


Hope this helps,

Mun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

GetBoldWords 1
GetBoldWords() 3
Obfuscate Email 1
Obfuscate 4
Regex 1
can my decompress method be written in a better way 3
Incrementing IPv6 address 1
Datagrid > DataList problem - Any clues? 1

Top