英文:
how to bold a text in message template in format string c#
问题
将以下部分翻译为中文:
如何使下面的“Code”加粗?
Code: {1}
创建日期:{2}
结果:
Code:123
创建日期:123
英文:
How do I make "Code" bold in the message below?
Code: {1}
Creation Date: {2}
results:
Code:123
Creation Date: 123
答案1
得分: 1
Sure, here's the translated code part:
您可以像下面这样从C#将粗体标签<b>添加到字符串的第一部分
string stringA = "abc";
string stringB = "123";
string stringC = "xyz";
string Final = "<b>" + stringA + "</b>" + stringB + stringC;
如果您希望具有更通用的方法,可以创建以下方法
/// <summary>
/// 格式化字符串的指定主值。
/// </summary>
/// <param name="mainvalue">主值。</param>
/// <param name="partvalue">部分值。</param>
/// <returns></returns>
public string formattedstring(string mainvalue, string partvalue)
{
return Regex.Replace(mainvalue, partvalue, @"<b>$0</b>", RegexOptions.IgnoreCase);
}
然后像下面这样调用上述方法
var result = this.formattedstring(Final, stringA);
Please note that I have corrected the method name from "formaatedstring" to "formattedstring" for consistency.
英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论