c# 用空格分割字符串_C#| 左用空格填充字符串
生活随笔
收集整理的這篇文章主要介紹了
c# 用空格分割字符串_C#| 左用空格填充字符串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
c# 用空格分割字符串
PadLeft() method is a library method of the String class. It is used to pad the string from the left side with spaces.
PadLeft()方法是String類的庫方法。 它用于從左側用空格填充字符串。
Syntax:
句法:
string string.PadLeft(int totalWidth);Here, totalWidth is the total number of characters of the string, if it is more than the length of the string, string will be padded with spaces, method returns the space padded string.
在這里, totalWidth是字符串的字符總數,如果大于字符串的長度,則將用空格填充字符串,方法將返回用空格填充的字符串。
Program:
程序:
using System;namespace ConsoleApplication1 {class Program{static void Main(string[] args){string str = "Hello world";Console.WriteLine("Demonstration of PadLeft method");Console.WriteLine(str.PadLeft(str.Length + 1));Console.WriteLine(str.PadLeft(str.Length + 2));Console.WriteLine(str.PadLeft(str.Length + 3));Console.WriteLine(str.PadLeft(str.Length + 4));Console.WriteLine(str.PadLeft(str.Length + 5));Console.WriteLine(); }} }Output
輸出量
Demonstration of PadLeft methodHello worldHello worldHello worldHello worldHello world翻譯自: https://www.includehelp.com/dot-net/left-padding-a-string-with-spaces-csharp.aspx
c# 用空格分割字符串
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的c# 用空格分割字符串_C#| 左用空格填充字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 枚举 示例_Java枚举nam
- 下一篇: matlab在绘图时分数,第三章_Mat