views:

2410

answers:

4

I want to right pad my string with blank spaces. The following function works for all characters except the blank.

myString.PadRight(50,"x")

Edit:

myString.PadRight(50) does pad a string with blank spaces, but when this string is used in the following statement, the blank padding is gone.

myCheckBox.Text = myString.PadRight(50)
+2  A: 

I think if you just omit the character specifier it will pad on the right with spaces.

var newString = myString.PadRight(50);

See the doc reference. It sure seems like it should work by specifying the space character as well, though. I don't know why it would treat it any differently than any other Unicode character.

tvanfosson
A: 

It sounds like this is for an asp.net page, in which case the problem is with how html treats whitespace. If you look at your source, the spaces are probably rendered to the client. However, the browser won't show them. Use a CSS style for the element instead to set the width or render   characters.

Joel Coehoorn
This is for a custom VB control from DotNetBar...
A: 

Do you really need that padding? Maybe you just want need to set alignment of text in your control?

Dmitriy Matveev
Its definitely padding...
A: 

How do you know the blank padding is wrong? I do not experience this when I try your code in VS 2005 with a dwindows.forms checkbox.

I guess that either the custom control removes the spaces or your observation is incorrect.

Renze de Waal
I think its the control because I know what effect the function should have...