如何使字符串的一部分加粗 [英] how to make a part of string bold

查看:154
本文介绍了如何使字符串的一部分加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string body1 =亲爱的用户,++用户名+



我希望字符串粗体的一部分像

亲爱的用户,Rahul我希望Rahul文字粗体......

string body1 = " Dear User," + " " + user name + ""

I want a part of string bold like
Dear user , Rahul i want Rahul text bold......

推荐答案

string 类不包含任何有关文本格式的信息(粗体,斜体等...)。

因此在简单字符串上指定粗体属性是不可能。



根据您的目标技术(Windows窗体,WPF等等),解决方案将有所不同:在Winforms中有一个 RichTextBox ,允许将多种格式应用于给定文本;在WPF和ASP.NET中,这更加简单,因为有一个特殊标记用于将粗体属性应用于文本。
string class does not hold any information about text formatting (bold, italic, etc...).
So specifying a bold attribute on a simple string is impossible.

Depending on your target technology (Windows Forms, WPF, etc...) the solution will be different : in Winforms there is a RichTextBox which allows to apply several formattings to a given text ; in WPF and ASP.NET this is more trivial as there is a special tag for applying bold attribute to a text.


这篇关于如何使字符串的一部分加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆