how to bold a text in message template in format string c#

358 Views Asked by At

How do I make "Code" bold in the message below?

Code: {1} Creation Date: {2}

results:

Code:123 Creation Date: 123

1

There are 1 best solutions below

1
user123456 On
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);