c# - String.Format() 问题

标签 c# .net string.format

当我使用 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/

相关文章:

.net - 在 LINQ 中有什么可能而不是 Lambda 吗?

.net - 使用 GoogleApisClient ServiceAccountCredential 调用 RequestAccessTokenAsync 抛出异常

c# - 具有十进制格式的C#string.format。

c# - String.Format 与 ToString()

c# - 在 MVC 中日期时间?不工作

c# - 在 C# 中执行 .NET IL 代码

c# - 使用类型为 DataType 的泛型方法

java - 如何让动态字符串出现在我的 View 中?

c# - 为什么这段代码在没有 unsafe 关键字的情况下也能工作?

c# - TimeSpan 中一天的非事件间隔