【问题标题】:Remove part from a string从字符串中删除部分
【发布时间】:2017-09-15 17:11:55
【问题描述】:

我正在使用 Swift 4 开发 iOS 应用程序。我正在将一些数据写入 Firebase 数据库(“FB-DB”)。读取数据时,应用会生成以下内容:

let sharedDataReceivedWithBraces = "[\(each.1)]"

print(sharedDataReceivedWithBraces)之后相应的控制台输出如下:

[{
id = "EEBEA75A-4DD0-4B30-84FB-1610A664276A";
key = "-Ku5VUHb5rbiy1ipFPL1";
code = 81358;
time = "14:06";
}]

我想从中删除大括号({})以进一步处理信息,但我为此苦苦挣扎。你能帮我如何让我的控制台的输出看起来像这样吗?

[
id = "EEBEA75A-4DD0-4B30-84FB-1610A664276A";
key = "-Ku5VUHb5rbiy1ipFPL1";
code = 81358;
time = "14:06";
]

非常感谢您的大力和耐心帮助!

干杯,

亚尼尼奥

【问题讨论】:

    标签: arrays swift string


    【解决方案1】:

    使用StringreplacingWithOccurences 完成此任务。

    let sharedDataWithoutBraces = "[\(each.1)]"
        .replacingOccurrences(of: "{", with: "")
        .replacingOccurrences(of: "}", with: "")
    

    【讨论】:

    • 你知道我如何将上面的输出转换成数组吗?
    • 你所说的“转化”是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 2012-03-27
    • 2020-09-03
    • 2011-01-18
    • 1970-01-01
    相关资源
    最近更新 更多