汉字字符串不够位数补空格

字符串后补空格

string test = "abc中文123";
string result = test + new string(' ', 16 - Encoding.GetEncoding("gb2312").GetBytes(test).Length);

显示结果 "abc中文123    "

字符串前补空格

string test = "abc中文123";
string result = new string(' ', 16 - Encoding.GetEncoding("gb2312").GetBytes(test).Length)+test ;

显示结果 "   abc中文123"

原文地址:https://www.cnblogs.com/amylis_chen/p/3245598.html