C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# PadRight() 获取新字符串

C# PadRight() 方法用于获取一个新字符串,该字符串通过在右侧用空格填充字符来左对齐该字符串中的字符,达到指定的总长度。

签名

句法 (Syntax)

public string PadRight(Int32 length)  
public string PadRight(Int32, Char)

范围

长度:它是一个整数类型参数。

返回

它返回一个字符串。


C# String PadRight() 方法示例

例子 (Example)

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


  • 使用社交账号登录,本站支持
全部评论(0)