This is a C# Program to perform padding in the string.
This C# Program Performs Padding in the String.
Here it creates a new string that consists of an original string that is padded with leading or trailing characters to a specified total length.
Here is source code of the C# Program to Perform Padding in the String. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Perform Padding in the String */ using System; namespace padd { class Program { static void Main(string[] args) { string myString = "CSHARP"; string newString; System.Console.WriteLine("String Before Padding : "); System.Console.WriteLine(myString); System.Console.WriteLine("String After Padding : "); newString = myString.PadLeft(10, ' '); newString = newString.PadRight(20, '*'); System.Console.Write("[" + newString + "]"); Console.Read(); } } }
This C# program is used to perform padding in the string. We have already defined a sentence using ‘myString’ variable. Here it creates a new string that consists of an original string that is padded with leading or trailing characters to a specified total length.
String Before Padding : CSHARP String After Padding : [ CSHARP**********]
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Check Computer Science Books
- Apply for C# Internship
- Check MCA Books
- Practice MCA MCQs
- Practice Computer Science MCQs