Adding whitespaces to a string in C#

前端 未结 4 1779
失恋的感觉
失恋的感觉 2021-01-03 21:58

I\'m getting a string as a parameter.

Every string should take 30 characters and after I check its length I want to add whitespaces to the end of the st

4条回答
  •  死守一世寂寞
    2021-01-03 22:35

    You can use String.PadRight for this.

    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.

    For example:

    string paddedParam = param.PadRight(30);
    

提交回复
热议问题