C# String PadRight()
C# String PadRight()
C# PadRight() 方法用于获取一个新字符串,该字符串通过在右侧填充空格来左对齐该字符串中的字符, 对于指定的总长度。
签名
public string PadRight(Int32 length)
public string PadRight(Int32, Char)
参数
长度: 是一个整型参数。
返回
它返回一个字符串。
C# String PadRight() 方法示例
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";// 8 length of characters
string s2 = s1.PadRight(15);
Console.Write(s2);//padding at right side (15-8=7)
Console.Write("lidihuo");//will be written after 7 white spaces
}
}
输出: