字符串后补空格

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"

相关文章:

  • 2022-12-23
  • 2021-06-14
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案