c# – Padding a string using PadRight method

Posted: April 1, 2015 in .Net4.0
Tags:

Sharing a small tip 🙂 If you want to add spaces to the end of a string,C# gives us method PadRight to do that.If the length of string is specified as 16 for eg and incase user enters only three characters and you want to add spaces to create a total length of 16,you can write as below.This example gets input from a textbox and adds spaces to the end of string entered.

this.txtLoginName.Text.ToString().PadRight(16);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s