EN
C# / .NET - string padding right
0 points
In this article, we would like to show you how to pad right indicated string in C#.
Quick solution:
xxxxxxxxxx
1
string text = "Example text";
2
3
Console.WriteLine(text.PadRight(15)); // Output: "Example text "
In this example, we use PadRight()
method to get string padded with spaces or with a specified Unicode character.
xxxxxxxxxx
1
using System;
2
using System.Linq;
3
4
public class Program
5
{
6
public static void Main()
7
{
8
string text = "Example text";
9
10
Console.WriteLine(text.PadRight(15));
11
Console.WriteLine(text.PadRight(5));
12
Console.WriteLine(text.PadRight(15, '*'));
13
}
14
}
Output:
xxxxxxxxxx
1
Example text
2
Example text
3
Example text***