Use the PadLeft() and PadRight() methods to align strings
using System;
class MainClass
{
public static void Main()
{
string[] myStrings = {"To", "be", "or", "not", "to", "be"};
string myString = String.Join(".", myStrings);
string myString14 = '(' + myString.PadLeft(20) + ')';
Console.WriteLine("'(' + myString.PadLeft(20) + ')' = " + myString14);
string myString15 = '(' + myString.PadLeft(20, '.') + ')';
Console.WriteLine("'(' + myString.PadLeft(20, '.') = " + myString15);
string myString16 = '(' + myString.PadRight(20) + ')';
Console.WriteLine("'(' + myString.PadRight(20) + ')' = " + myString16);
string myString17 = '(' + myString.PadRight(20, '.') + ')';
Console.WriteLine("'(' + myString.PadRight(20, '.') + ')' = " + myString17);
}
}
Output '(' + myString.PadLeft(20) + ')' = ( To.be.or.not.to.be)
'(' + myString.PadLeft(20, '.') = (..To.be.or.not.to.be)
'(' + myString.PadRight(20) + ')' = (To.be.or.not.to.be )
'(' + myString.PadRight(20, '.') + ')' = (To.be.or.not.to.be..)
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
|