Adding whitespaces to a string in C#

前端 未结 4 1683
失恋的感觉
失恋的感觉 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:24

    Use String.PadRight which will space out a string so it is as long as the int provided.

    var str = "hello world";
    var padded = str.PadRight(30);
    // padded = "hello world                   "
    

提交回复
热议问题