1.在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位。

    PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度

    PadRight(int totalWidth, char paddingChar) //在字符串右边用 paddingChar 补足 totalWidth 长度

2.String.PadLeft(int length,char ReplaceStr):如果字符串的长度小于length,则在字符串的左边用ReplaceStr填充。  

实例:         string num=12         num.PadLeft(4, '0'); //结果为为 '0012'        //看字符串长度是否满足4位,不满足则在字符串左边以"0"补足

相关文章:

  • 2021-08-08
  • 2021-07-19
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-02-06
  • 2022-01-06
  • 2022-12-23
  • 2021-07-09
相关资源
相似解决方案