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類的庫(kù)方法。 它用于從左側(cè)用空格填充字符串。
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是字符串的字符總數(shù),如果大于字符串的長(zhǎng)度,則將用空格填充字符串,方法將返回用空格填充的字符串。
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# 用空格分割字符串
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的c# 用空格分割字符串_C#| 左用空格填充字符串的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java 枚举 示例_Java枚举nam
- 下一篇: c#hello world_C#| 打印