内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
如何将“0”填充添加到字符串,以便我的字符串长度始终为4?
例
If input "1", 3 padding is added = 0001 If input "25", 2 padding is added = 0025 If input "301", 1 padding is added = 0301 If input "4501", 0 padding is added = 4501
你可以使用PadLeft
var newString = Your_String.PadLeft(4, '0');
myInt.ToString("D4");
Swoole · PHP开发工程师 (已认证)
Dingda · 站长 (已认证)
社区 · 运营 (已认证)
腾讯 · 社区运营 (已认证)
扫码关注云+社区