Showing posts with label add space left side of string. Show all posts
Showing posts with label add space left side of string. Show all posts

Add space to string in c#

Hi, here i have to remind  we can add specified space or byte to existing string.

string spacestr = "123";
spacestr = spacestr .ToString().PadRight(10 , '*'); //for asterisk   
(OR)
spacestring  = spacestring  .ToString().PadRight(10 , ' '); //for space

now 'spacestr ' value will be :123*******, the seven * will added to right side of the 'spacestr .
 (OR)
now 'spacestr ' value will be :123       , the seven sapce will added to right side of the 'spacestr .

if we need to add space left side of str
spacestr = spacestr .ToString().PadLeft(10 , '*');

now 'spacestr ' value will be :*******123, the * will added to left side of the spacestr .
Probably we need space, we replace space ' ' character instead of  asterisk '*'