[C#] 字串補0

  • 20292
  • 0

摘要:[C#] 字串補0

 

用PadLeft函式

PadLeft(固定幾位數,向左填補字元)

使用方式

string str = "9";

str.PadLeft(2, '0') => 09

str.PadLeft(4, '0') => 0009

有向左補0,也就有向右補0

PadRight(固定幾位數,向右填補字元)

str.PadRight(2, '0') => 90

str.PadRight(4, '0') => 9000

 

 






Y2J's Life:http://kimenyeh.blogspot.tw/