我得到一个 string
作为参数。
每个字符串应包含 30 个字符,在检查其长度后,我想在字符串末尾添加空格。
例如。如果传递的字符串是 25 个字符长,我想再添加 5 个空格。
问题是,如何向字符串添加空格?
最佳答案
您可以使用 String.PadRight为此。
Returns a new string that left-aligns the characters in this string by padding them with spaces on the right, for a specified total length.
例如:
string paddedParam = param.PadRight(30);
关于c# - 在 C# 中向字符串添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15851730/