【问题标题】:How to remove spaces in between from a String in Swift? [duplicate]如何从 Swift 中的字符串中删除空格? [复制]
【发布时间】:2022-01-24 07:43:09
【问题描述】:

我需要删除中间的空格。

例如:"000 111 2222"

我很想拥有:"0001112222"

我该怎么做?

【问题讨论】:

  • 请向我们展示您最近尝试的代码以及您遇到的问题
  • 你可以试试"000 111 2222".replacingOccurrences(of: " ", with: "") 这样的方法,但我希望有更好的方法

标签: ios swift string


【解决方案1】:
var str = "000 111 2222"
let newString = str.replacingOccurrences(of: " ", with: "", options: .literal, range: nil)
print(newString)

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 2018-03-13
    • 2013-12-11
    • 2018-08-15
    • 2011-12-07
    • 2015-04-17
    • 2017-04-14
    相关资源
    最近更新 更多