C# PadRight() 方法用于获取一个新字符串,该字符串通过在右侧用空格填充字符来左对齐该字符串中的字符,达到指定的总长度。
public string PadRight(Int32 length) public string PadRight(Int32, Char)
长度:它是一个整数类型参数。
它返回一个字符串。
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("RocSchool");//will be written after 7 white spaces } }
输出:
Hello C# RocSchool