指定格式 | 函数用法 | 输出结果 |
固定宽度右对齐 | String.Format("{0, 4}", num) | “ 1” |
固定宽度左对齐 | String.Format("{0, -4}", num) | “1 ” |
用0填充 | String.Format("{0:D4}", num) 或者 String.Format("{0:0000}", num) | “0001” |
固定宽度并用0填充 | String.Format("{0, 8:D4}", num) | “ 0001” |
指定格式 | 函数用法 | 输出结果 |
固定宽度右对齐 | String.Format("{0, 4}", num) | “ 1” |
固定宽度左对齐 | String.Format("{0, -4}", num) | “1 ” |
用0填充 | String.Format("{0:D4}", num) 或者 String.Format("{0:0000}", num) | “0001” |
固定宽度并用0填充 | String.Format("{0, 8:D4}", num) | “ 0001” |