上代码
string SetFormat(string str, int count)
{
if (string.IsNullOrEmpty(str))
{
return new string('*', count) { };
}
int len = count - Encoding.Default.GetByteCount(str);
if (len <= 0)
{
return str;
}
else
{
if (len%3==0)
{
len += 1;//正好是3的整数倍的时候, 就不管用了
}
return str + new string('*', len) + " ";
}
}
其中的count应填3的整数倍,比如最长有5个汉字,则count填15,有10个汉字count就填30
看效果:

原创不易,点赞支持一下