/// <summary>
/// 替换 把不是\f0\fs18的替换成是
/// </summary>
/// <returns></returns>
public static string ReplaceStr(this string oldReplaceStr, string newReplaceStr = "\\f0\\fs18")
{
if (string.IsNullOrEmpty(oldReplaceStr)) return string.Empty;
var str = oldReplaceStr;
var sChat = "\\f0\\fs";
int length = 0;
while (oldReplaceStr.Contains(sChat))
{
var index = oldReplaceStr.IndexOf(sChat) + sChat.Length;
oldReplaceStr = oldReplaceStr.Substring(index);
++length;
}
oldReplaceStr = str;
int count = 0;
//判断是否包含标识字体大小的字符串
while (str.Contains(sChat))
{
//获取第一个标记的位置
var index = str.IndexOf(sChat) + sChat.Length;
var size = str.Substring(index, 2);
if (size != "18")
{
str = str.Remove(index, 2);
str = str.Insert(index, "18");
oldReplaceStr = str;
++count;
}
else
{
if (count != length) ++count;
else break;
}
}
return oldReplaceStr;
}
或者
skintxtRChat.Font = this.Font;