我必须以特殊格式打印出count变量(非负数):
例如:
2 -> "00000000000000000002" // <- The length of each string is 20
30 -> "00000000000000000030"
123 -> "00000000000000000123"
Run Code Online (Sandbox Code Playgroud)
在.Net中实现这一目标的最佳方法是什么?
你可以使用PadLeft:
String value = "2";
String result = value.PadLeft(20, '0'); // <- 20 is desired string length, '0' - padding
Run Code Online (Sandbox Code Playgroud)
另一种可能性(如果你有整数值)是格式化:
int value = 2;
String result = value.ToString("D20");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1176 次 |
| 最近记录: |