【发布时间】:2021-12-27 01:11:27
【问题描述】:
我需要打印一个字符串,就好像 Mexican Wave 正在通过字符串中的每个字符:
wave("hello") -> ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
目前我停在:
var str = "hel lo"
var arr = [String]()
str = str.lowercased()
str = str.replacingOccurrences(of: " ", with: "")
for i in str {
arr.append (str.replacingOccurrences(of: "\(i)", with: i.uppercased()))
}
print(arr)
【问题讨论】: