Q:
C# program to perform left padding without using PadLeft() method
belongs to collection: C# Basic Programs | String programs
C# Basic Programs | String programs
- Comparing two strings in C#
- Demonstrate the example of Copy method of String class in C#
- Demonstrate the example of IndexOf() method of string class in C#
- Compare strings using Equals() method in C#
- Explain LastIndexOf() method of String class with Example in C#
- Explain String.Split() method of String class in C# with an Example
- How to convert string into uppercase in C#?
- How to convert string into lowercase in C#?
- How to get substring from a string in C#?
- How to trim the string in C#, an example of String.Trim() method?
- How to trim leading spaces of string using String.TrimStart() in C#?
- How to trim trailing spaces of string using String.TrimEnd() in C#?
- How to pad string from left using String.PadLeft() in C#?
- How to pad string from right using String.PadRight() in C#?
- Check whether string ends with given substring or not using String.EndsWith() in C#?
- How to remove given substring from a string using String.Remove() in C#?
- How to replace a character with another character in a string in C#?
- C# program to count the frequency of the specified word in the given string
- C# program to trim a specified string
- C# program to trim a specified string from the left side
- C# program to trim a specified string from the right side
- C# program to split a string using the Split() method of String class
- C# program to extract only numbers from a specified string using the Split() method
- C# program to get the length of the string
- C# program to replace a substring within a specified string
- C# program to find the occurrence of the specified word in a given string
- C# program to convert a string from lowercase to uppercase
- C# program to print the abbreviation of a given string
- C# program to print the list of all possible substrings of a specified string
- C# program to count the total number of digits in an alpha-numeric string
- C# program to concatenate the two strings using a predefined method
- C# program to reverse a given string without using the predefined method
- C# program to perform left padding without using PadLeft() method
- C# program to perform the right padding without using the PadRight() method
- C# program to count the total number of vowels in a given string
- C# program to generate random strings
- C# program to encrypt and decrypt a string using Rijndael key algorithm
- C# program to count the lines in a given string
Program:
The source code to perform left padding without using PadLeft() method is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created two static methods StrPadLeft() and Main(). The StrPadLeft() method is used to pad the string with specified character by a given number of times.
In the Main() method, we read the value of the string and passed to the StrPadLeft() method that returned the left padded string and then finally prints the result on the console screen.