String padding
In this chapter you will learn:
Padding string
Padding string is to add specified character to a string to a given length.
We can choose the pad left or right.
using System;/*j a va 2 s.com*/
class Sample
{
public static void Main()
{
string s = "java2s.com";
s = s.PadLeft(20,'=');
Console.WriteLine(s);
s = s.PadRight(40,'+');
Console.WriteLine(s);
}
}
The output:
Pad with space
By default the Pad functions add space to strings.
using System;//from j a va 2s.co m
class MainClass
{
public static void Main()
{
string myString = "java2s.com";
string myString14 = myString.PadLeft(20);
Console.WriteLine(myString14);
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » String