最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift字符串替换

Swift crifan 2541浏览 0评论

把:

{\"0\":{\"user-12059519-b8e0-4860-bd20-4e74840fb70a\":0,\"user-2a00aaac-074c-4985-84e9-7ee724742d53\":0,\"user-26d642fc-6d1f-40ef-9220-658b98ccb6bd\":0,\"user-757f84e3-7b60-4264-a21f-2ea48e3b922c\":0,\"user-b28a76c7-0c58-4092-abf6-42f1878484d3\":0,\"user-ef5e0d35-7858-4777-9299-3c0e69a933c6\":0,\"user-736899be-1d71-4f0a-9186-04ea3a136198\":0},\"1\":{\"group-25edbda2-9e6b-49f6-a45a-73f2052565bb\":0,\"group-694475a6-a718-43ce-a5bc-95fbba00f524\":0},\"2\":{\"group-5d68f640-f6ef-4c1a-a705-bb6d1fa8435e\":0,\"group-67f90e86-8b4c-4cc0-8872-802a80c64c2d\":0,\"group-0ff80a07-f7f1-484a-9784-795b62d5a049\":0},\"3\":{\"user-fe78066b-5085-4d9b-a731-1746efa80968\":0,\"user-62d41ad4-11d4-4c0f-b1b1-5019b7c77663\":0,\"user-00000000-0000-0000-0000-000000000002\":0,\"user-736899be-1d71-4f0a-9186-04ea3a136198\":0,\"user-757f84e3-7b60-4264-a21f-2ea48e3b922c\":0,\"user-79aa0f8b-c346-4668-bddd-9b5c9e936117\":0,\"user-3ec11e86-29ad-4576-be9b-8228e186e8a1\":0,\"user-b18b54f8-287b-4794-a4ed-15adfce8d578\":0,\"user-9c84c90c-e1bd-45a8-b401-c97d36c8b7bc\":0,\"user-12059519-b8e0-4860-bd20-4e74840fb70a\":0,\"user-2a00aaac-074c-4985-84e9-7ee724742d53\":0,\"user-cbcaae2f-ecec-44b0-84fb-c99dd4c4726a\":0,\"user-26d642fc-6d1f-40ef-9220-658b98ccb6bd\":0,\"user-64d8401d-94b5-4ff3-92a4-581e153a1fc9\":0,\"user-b28a76c7-0c58-4092-abf6-42f1878484d3\":0,\"group-0463c067-ecdf-4d91-baf6-3583679379cb\":0,\"group-2a7ea22d-a74a-4fde-ac31-691b301cd89c\":0,\"group-bc6c9b32-d100-4555-8d55-8c40f6a6ae54\":0}}

中的

\"

换成

swift string replace

Any way to replace characters on Swift String? – Stack Overflow

使用:

               let sceneStrNoSlash = sceneStr.stringByReplacingOccurrencesOfString("\\\"", withString: "\"")
                print("sceneStrNoSlash=\(sceneStrNoSlash)")
                //sceneStrNoSlash={"0":{"user-12059519-b8e0-4860-bd20-4e74840fb70a":0,"user-2a00aaac-074c-4985-84e9-7ee724742d53":0,"user-26d642fc-6d1f-40ef-9220-658b98ccb6bd":0,"user-757f84e3-7b60-4264-a21f-2ea48e3b922c":0,"user-b28a76c7-0c58-4092-abf6-42f1878484d3":0,"user-ef5e0d35-7858-4777-9299-3c0e69a933c6":0,"user-736899be-1d71-4f0a-9186-04ea3a136198":0},"1":{"group-25edbda2-9e6b-49f6-a45a-73f2052565bb":0,"group-694475a6-a718-43ce-a5bc-95fbba00f524":0},"2":{"group-5d68f640-f6ef-4c1a-a705-bb6d1fa8435e":0,"group-67f90e86-8b4c-4cc0-8872-802a80c64c2d":0,"group-0ff80a07-f7f1-484a-9784-795b62d5a049":0},"3":{"user-fe78066b-5085-4d9b-a731-1746efa80968":0,"user-62d41ad4-11d4-4c0f-b1b1-5019b7c77663":0,"user-00000000-0000-0000-0000-000000000002":0,"user-736899be-1d71-4f0a-9186-04ea3a136198":0,"user-757f84e3-7b60-4264-a21f-2ea48e3b922c":0,"user-79aa0f8b-c346-4668-bddd-9b5c9e936117":0,"user-3ec11e86-29ad-4576-be9b-8228e186e8a1":0,"user-b18b54f8-287b-4794-a4ed-15adfce8d578":0,"user-9c84c90c-e1bd-45a8-b401-c97d36c8b7bc":0,"user-12059519-b8e0-4860-bd20-4e74840fb70a":0,"user-2a00aaac-074c-4985-84e9-7ee724742d53":0,"user-cbcaae2f-ecec-44b0-84fb-c99dd4c4726a":0,"user-26d642fc-6d1f-40ef-9220-658b98ccb6bd":0,"user-64d8401d-94b5-4ff3-92a4-581e153a1fc9":0,"user-b28a76c7-0c58-4092-abf6-42f1878484d3":0,"group-0463c067-ecdf-4d91-baf6-3583679379cb":0,"group-2a7ea22d-a74a-4fde-ac31-691b301cd89c":0,"group-bc6c9b32-d100-4555-8d55-8c40f6a6ae54":0,"group-2484009d-8fa1-4a0b-922f-88ef0f826ec0":0,"group-647da8e4-ecf5-4720-9517-89dbc0b0cffe":0}}
               
                /*
                {
                    "0": {
                        "user-12059519-b8e0-4860-bd20-4e74840fb70a": 0,
                        "user-2a00aaac-074c-4985-84e9-7ee724742d53": 0,
                        "user-26d642fc-6d1f-40ef-9220-658b98ccb6bd": 0,
                        "user-757f84e3-7b60-4264-a21f-2ea48e3b922c": 0,
                        "user-b28a76c7-0c58-4092-abf6-42f1878484d3": 0,
                        "user-ef5e0d35-7858-4777-9299-3c0e69a933c6": 0,
                        "user-736899be-1d71-4f0a-9186-04ea3a136198": 0
                    },
                    "1": {
                        "group-25edbda2-9e6b-49f6-a45a-73f2052565bb": 0,
                        "group-694475a6-a718-43ce-a5bc-95fbba00f524": 0
                    },
                    "2": {
                        "group-5d68f640-f6ef-4c1a-a705-bb6d1fa8435e": 0,
                        "group-67f90e86-8b4c-4cc0-8872-802a80c64c2d": 0,
                        "group-0ff80a07-f7f1-484a-9784-795b62d5a049": 0
                    },
                    "3": {
                        "user-fe78066b-5085-4d9b-a731-1746efa80968": 0,
                        "user-62d41ad4-11d4-4c0f-b1b1-5019b7c77663": 0,
                        "user-00000000-0000-0000-0000-000000000002": 0,
                        "user-736899be-1d71-4f0a-9186-04ea3a136198": 0,
                        "user-757f84e3-7b60-4264-a21f-2ea48e3b922c": 0,
                        "user-79aa0f8b-c346-4668-bddd-9b5c9e936117": 0,
                        "user-3ec11e86-29ad-4576-be9b-8228e186e8a1": 0,
                        "user-b18b54f8-287b-4794-a4ed-15adfce8d578": 0,
                        "user-9c84c90c-e1bd-45a8-b401-c97d36c8b7bc": 0,
                        "user-12059519-b8e0-4860-bd20-4e74840fb70a": 0,
                        "user-2a00aaac-074c-4985-84e9-7ee724742d53": 0,
                        "user-cbcaae2f-ecec-44b0-84fb-c99dd4c4726a": 0,
                        "user-26d642fc-6d1f-40ef-9220-658b98ccb6bd": 0,
                        "user-64d8401d-94b5-4ff3-92a4-581e153a1fc9": 0,
                        "user-b28a76c7-0c58-4092-abf6-42f1878484d3": 0,
                        "group-0463c067-ecdf-4d91-baf6-3583679379cb": 0,
                        "group-2a7ea22d-a74a-4fde-ac31-691b301cd89c": 0,
                        "group-bc6c9b32-d100-4555-8d55-8c40f6a6ae54": 0,
                        "group-2484009d-8fa1-4a0b-922f-88ef0f826ec0": 0,
                        "group-647da8e4-ecf5-4720-9517-89dbc0b0cffe": 0
                    }
                }
                */

即可。

[总结]

字符串中替换某个(子)字符(串)的话,可以用:

originStr.stringByReplacingOccurrencesOfString(strToReplace, withString: replacedStr)

转载请注明:在路上 » [已解决]swift字符串替换

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.187 seconds, using 22.04MB memory