补位PadLeft()与PadRight()

作者:追风剑情 发布于:2018-11-27 21:22 分类:C#

示例

  1. using System.Linq;
  2. using System.Text;
  3. using System.Threading.Tasks;
  4. using System.Reflection;
  5.  
  6. namespace Test2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int code = 31;
  13. string padleft = Convert.ToString(code, 16).PadLeft(6, '0');
  14. string padright = Convert.ToString(code, 16).PadRight(6, '0');
  15. Console.WriteLine("左补位: " + padleft);
  16. Console.WriteLine("右补位: " + padright);
  17. Console.Read();
  18. }
  19. }
  20. }

运行测试

1111.png

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号