C# 输出固定长度 自动补0

C# 输出固定长度 自动补0

//固定长度字符串处理
//1.int类型转固定长度
Console.WriteLine(string.Format("{0:D5}", 123));
Console.WriteLine(string.Format("{0:D5}", 456));
//2.字符串转固定长度
//使用PadLeft方法可以自定义填充值
string s = "123";
Console.WriteLine(s.PadLeft(10));
Console.WriteLine(s.PadLeft(10, '0'));
Console.WriteLine(s.PadRight(10));
Console.WriteLine(s.PadRight(10, '0'));

猜你喜欢

转载自blog.csdn.net/weixin_44054505/article/details/101061095