Create a string with n blank spaces or other repeated character

后端 未结 4 1957
一生所求
一生所求 2020-12-15 05:55

I want to make a string with n blank spaces using Swift, but without using a for loop or manually like this:

// string with 5-blank spa         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 06:21

    I think we can play with stringbyPaddingToLength

    something like this should work:

    var str = " ";
    var str2 = str.stringByPaddingToLength(20, withString: " ", startingAtIndex: 0);
    

提交回复
热议问题