C#教程
C#控制语句
C#函数
C#数组
C#面向对象
C#命名空间和异常
C#文件IO
C#集合
C#多线程
C#其它

C# String PadLeft()

C# String PadLeft()

C# PadLeft() 方法用于获取一个新字符串,如果字符串长度小于指定长度。
例如,假设您将"hello C#"作为具有 8 个字符长度的字符串,并且您为 padleft 传递了 10 个字符,它将在右侧的两个空格之后移动字符串。这意味着 PadLeft() 方法为指定长度的字符串提供填充。用于格式化字符串内容。

签名

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

参数

长度: 是一个整型参数,用于传递padding。

返回

返回字符串。

C# String PadLeft() 方法示例

using System; 
    		
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
        string s1 = "Hello C#";// 8 length of characters
        string s2 = s1.PadLeft(10);//(10-8=2) adds 2 whitespaces at the left side
        Console.WriteLine(s2);
      }  
    }  
输出:
  Hello C#
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4