.net 如何在消息模板中以字符串格式加粗文本C#

jogvjijk  于 2023-05-19  发布在  .NET
关注(0)|答案(1)|浏览(164)

如何在下面的消息中将“代码”加粗?
代码:{1}创建日期:{二}
结果:

编码:123创建日期:123

2ul0zpep

2ul0zpep1#

You can add bold tag <b> from c# to first part of string like below

 string stringA = "abc";

                string stringB = "123";

                string stringC = "xyz";

                string Final = "<b>" + stringA +"</b>" + stringB + stringC;
If you want to have a more generic approach you can create a method like below

/// <summary>
        /// Formaatedstrings the specified mainvalue.
        /// </summary>
        /// <param name="mainvalue">The mainvalue.</param>
        /// <param name="partvalue">The partvalue.</param>
        /// <returns></returns>
        public string formaatedstring(string mainvalue, string partvalue)
        {
            return Regex.Replace(mainvalue, partvalue, @"<b>$0</b>", RegexOptions.IgnoreCase);
        }
and then call above method like below

var result = this.formaatedstring(Final, stringA);

相关问题