GetBoldWords()

  • Thread starter Thread starter Aaron
  • Start date Start date
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
 
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
 
Back
Top