Method for adding blank space after checking string minimum length,if string enter is not equal to minimum length defined then add blank space after the string to full fill the minimum length condition ? ?
example : minimum length =30
and string = "anuragsaraswat123abc" 20 character
then automatically find the diff between minimum length of string and available string and add blank space. Suggest me the method
This is covered in the framework with String.PadLeft and String.PadRight
string MyString = "Hello World!";
Console.WriteLine(MyString.PadRight(30, ' '));
You can use String.PadRight Method for that.
Returns a new string that left-aligns the characters in this string by padding them on the right with a specified Unicode character, for a specified total length.
static string YourMethod(string s)
{
return s.Length < 30 ? s.PadRight(30 - s.Length, ' ') : s;
}
Here is a DEMO.
Note: Since you can't see the blanks, it doesn't mean they are not there ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With