我想用空格右填充我的字符串。以下函数适用于除空白以外的所有字符。
myString.PadRight(50,"x")
编辑:
myString.PadRight(50) 确实用空格填充字符串,但是当在以下语句中使用此字符串时,空格填充消失了。
myCheckBox.Text = myString.PadRight(50)
我认为如果您只是省略字符说明符,它将在右侧填充空格。
var newString = myString.PadRight(50);
请参阅文档参考。不过,它似乎也应该通过指定空格字符来工作。我不知道为什么它会与任何其他 Unicode 字符不同地对待它。
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.
听起来这是针对 asp.net 页面的,在这种情况下,问题在于 html 如何处理空格。如果您查看源代码,则空间可能会呈现给客户端。但是,浏览器不会显示它们。改为使用元素的 CSS 样式来设置宽度或渲染
字符。
你真的需要那个填充物吗?也许您只想在控件中设置文本对齐方式?