温馨提示×

C#中PadLeft方法的语法和参数说明是什么

c#
小樊
86
2024-08-18 06:00:34
栏目: 编程语言

PadLeft方法用于在字符串的左侧填充指定的字符,使字符串达到指定的长度。其语法如下:

public string PadLeft(int totalWidth, char paddingChar)

参数说明:

  • totalWidth:指定填充后字符串的总长度。
  • paddingChar:指定用于填充的字符。

示例:

string str = "123";
string paddedStr = str.PadLeft(5, '0');
Console.WriteLine(paddedStr); // 输出:00123

0