當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# String PadRight()用法及代碼示例

C# PadRight() 方法用於獲取一個新字符串,該字符串 left-aligns 該字符串中的字符通過在右側填充空格,達到指定的總長度。

簽名

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

參數

length:它是一個整數類型參數。

返回

它返回一個字符串。

C# 字符串 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("JavaTpoint");//will be written after 7 white spaces
       }  
    }

輸出:

Hello C#       JavaTpoint




相關用法


注:本文由純淨天空篩選整理自 C# String PadRight()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。