Unity 字符串中英文、数字对齐

上代码

    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的整数倍的时候,\t 就不管用了
            }
            return str + new string('*', len) + "\t";
        }
    }

  其中的count应填3的整数倍,比如最长有5个汉字,则count填15,有10个汉字count就填30

看效果:

 

 原创不易,点赞支持一下

posted on 2021-10-18 20:06  Jason_c  阅读(200)  评论(0编辑  收藏  举报