【发布时间】:2022-01-24 07:43:09
【问题描述】:
我需要删除中间的空格。
例如:"000 111 2222"
我很想拥有:"0001112222"
我该怎么做?
【问题讨论】:
-
请向我们展示您最近尝试的代码以及您遇到的问题
-
你可以试试
"000 111 2222".replacingOccurrences(of: " ", with: "")这样的方法,但我希望有更好的方法
我需要删除中间的空格。
例如:"000 111 2222"
我很想拥有:"0001112222"
我该怎么做?
【问题讨论】:
"000 111 2222".replacingOccurrences(of: " ", with: "") 这样的方法,但我希望有更好的方法
var str = "000 111 2222"
let newString = str.replacingOccurrences(of: " ", with: "", options: .literal, range: nil)
print(newString)
【讨论】: