C# .NET - change font to bold. - Asked By shah zeb on 30-Nov-11 05:53 AM

i need a function in csharp which will check in a for a string in a text.(May be ASp.NEt label/textbox text). the function should check if a particular text exist in it. It should make it the text bold.

How this should be done?


Jitendra Faye replied to shah zeb on 30-Nov-11 06:13 AM
Use this code-

protected void Button1_Click(object sender, EventArgs e)


string str="gsdahfgsdaj";



Label1.Font.Bold =

true ;




Try this and let me know.
shah zeb replied to Jitendra Faye on 30-Nov-11 06:20 AM
i dont want to make the entire text to bold.
Only that part should be bolder which is found.
Jitendra Faye replied to shah zeb on 30-Nov-11 07:09 AM
For that you this code-

Label1.Text = "Hello <b>your Text</b> world";
dipa ahuja replied to shah zeb on 30-Nov-11 07:26 AM
You can use stringBuilder For this purpose

<asp:Label ID="Label1" runat="server" Text="Hello World! How are you all"></asp:Label>

using System.Text;
protected void Button1_Click(object sender, EventArgs e)
  StringBuilder str = new StringBuilder();
  string[] data = Label1.Text.Split(' ');
  foreach (string s in data)
    if (s.Contains("World"))
      str.Append("<b><font color='green'>");
      str.Append(" " + s);