当我使用 string.Format()
格式化字符串时,我希望能够表明我想要格式化该值并在末尾填充一定量的空格。
例如,假设我有以下内容:
string.Format("{0}", myStringValue);
我希望能够告诉 Format 函数格式化值,如果它少于 50 个字符,填充它(用空格),使其长度为 50 个字符。
这可以做到吗?
最佳答案
试试这个:
string.Format("{0,50}",myStringValue);
或
string.Format("{0,-50}",myStringValue);
关于c# - String.Format() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5523391/