<分区>
如何在不使用循环的情况下创建由相同字符组成的给定长度的字符串?
即:创建一个长度为 10 个字符的字符串,其中每个字符都是一个星号:**********
类似于此approach in Java : new String(new char[n]).replace("\0", s);
<分区>
如何在不使用循环的情况下创建由相同字符组成的给定长度的字符串?
即:创建一个长度为 10 个字符的字符串,其中每个字符都是一个星号:**********
类似于此approach in Java : new String(new char[n]).replace("\0", s);
最佳答案
有一个 String
初始化程序:
init(repeating repeatedValue: String, count: Int)
Description
Creates a new string representing the given string repeated the specified number of times.
let string = String(repeating: "*", count: 10)
关于Swift:给定长度的相同字符创建字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40711645/