C# String PadRight() 字符串右填充方法
String 类的 PadRight()
方法返回一个指定长度的新字符串,其中当前字符串的末尾用空格或指定字符填充。
示例
using System;
namespace CsharpString {
class Test {
public static void Main(string [] args) {
string str = "Icecream";
string result;
// 返回长度为 15 的字符串
// 右侧用空格填充
result = str.PadRight(15);
Console.WriteLine("|{0}|", result);
Console.ReadLine();
}
}
}
// 输出:|Icecream |
PadRight() 方法语法
字符串 PadRight()
方法的语法是:
PadRight(int totalWidth, char paddingChar)