返回一个新字符串,该字符串通过在此实例中的字符左侧填充空格来达到指定的总长度,从而实现右对齐。

 

命名空间:  System
程序集:  mscorlib(在 mscorlib.dll 中)
 
public string PadLeft(
int totalWidth
)

参数

totalWidth
类型:System.Int32
结果字符串中的字符数,等于原始字符数加上任何其他填充字符。

返回值

类型:System.String
totalWidth 小于此实例的长度,则为与此实例相同的新字符串。
异常 条件
ArgumentOutOfRangeException

totalWidth 小于零。

Unicode 空格定义为十六进制的 0x20。

这意味着当对从右向左的语言使用该方法时,它将填充字符串的右部。

注意

totalWidth 个字符。

PadLeft 方法。

string str = "BBQ and Slaw";
Console.WriteLine(str.PadLeft(15));  // Displays "   BBQ and Slaw".
Console.WriteLine(str.PadLeft(5));   // Displays "BBQ and Slaw".
转自MSDN:http://msdn.microsoft.com/zh-cn/library/0zk6ydzx

相关文章:

  • 2021-11-20
  • 2021-11-10
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2021-12-08
  • 2022-02-02
  • 2022-12-23
  • 2021-05-23
  • 2021-11-17
  • 2021-08-24
  • 2021-12-27
相关资源
相似解决方案