1. <i id='FtnO4'><tr id='FtnO4'><dt id='FtnO4'><q id='FtnO4'><span id='FtnO4'><b id='FtnO4'><form id='FtnO4'><ins id='FtnO4'></ins><ul id='FtnO4'></ul><sub id='FtnO4'></sub></form><legend id='FtnO4'></legend><bdo id='FtnO4'><pre id='FtnO4'><center id='FtnO4'></center></pre></bdo></b><th id='FtnO4'></th></span></q></dt></tr></i><div id='FtnO4'><tfoot id='FtnO4'></tfoot><dl id='FtnO4'><fieldset id='FtnO4'></fieldset></dl></div>

  2. <legend id='FtnO4'><style id='FtnO4'><dir id='FtnO4'><q id='FtnO4'></q></dir></style></legend>

    <small id='FtnO4'></small><noframes id='FtnO4'>

      <bdo id='FtnO4'></bdo><ul id='FtnO4'></ul>
  3. <tfoot id='FtnO4'></tfoot>

      如何在 Swift 中从字符串中删除数字

      How to remove numbers from a String in Swift(如何在 Swift 中从字符串中删除数字)

    1. <tfoot id='gzXsV'></tfoot>

      <small id='gzXsV'></small><noframes id='gzXsV'>

        • <bdo id='gzXsV'></bdo><ul id='gzXsV'></ul>

              <legend id='gzXsV'><style id='gzXsV'><dir id='gzXsV'><q id='gzXsV'></q></dir></style></legend>
              <i id='gzXsV'><tr id='gzXsV'><dt id='gzXsV'><q id='gzXsV'><span id='gzXsV'><b id='gzXsV'><form id='gzXsV'><ins id='gzXsV'></ins><ul id='gzXsV'></ul><sub id='gzXsV'></sub></form><legend id='gzXsV'></legend><bdo id='gzXsV'><pre id='gzXsV'><center id='gzXsV'></center></pre></bdo></b><th id='gzXsV'></th></span></q></dt></tr></i><div id='gzXsV'><tfoot id='gzXsV'></tfoot><dl id='gzXsV'><fieldset id='gzXsV'></fieldset></dl></div>
                  <tbody id='gzXsV'></tbody>
              • 本文介绍了如何在 Swift 中从字符串中删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个字符串,例如 75003 Paris, France"Syracuse, NY 13205, USA".

                I have a String like "75003 Paris, France" or "Syracuse, NY 13205, USA".

                我想使用相同的代码从这些字符串中删除所有这些数字.

                I want to use the same code to remove all those numbers out of those Strings.

                预期的输出是法国巴黎"美国纽约州锡拉丘兹".

                我怎样才能做到这一点?

                How can I achieve that?

                推荐答案

                你可以用 NSCharacterSet

                var str = "75003 Paris, France"
                
                var stringWithoutDigit = (str.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet()) as NSArray).componentsJoinedByString("")
                
                println(stringWithoutDigit)
                

                输出:

                Paris, France
                

                参考自:https://stackoverflow.com/a/1426819/3202193

                Swift 4.x:

                let str = "75003 Paris, France"
                
                let stringWithoutDigit = (str.components(separatedBy: CharacterSet.decimalDigits)).joined(separator: "")
                
                print(stringWithoutDigit)
                

                这篇关于如何在 Swift 中从字符串中删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))
                How can you rotate text for UIButton and UILabel in Swift?(如何在 Swift 中旋转 UIButton 和 UILabel 的文本?)
                iOS 8+ framework with nested embedded framework(带有嵌套嵌入式框架的 iOS 8+ 框架)
                Import Framework in Swift Project, Xcode(Swift 项目、Xcode 中的导入框架)
                Signing embedded framework not working in Xcode 11.2.1(签署嵌入式框架在 Xcode 11.2.1 中不起作用)
                Xcode 6.1: file was built for x86_64 which is not the architecture being linked (i386)(Xcode 6.1:文件是为 x86_64 构建的,它不是被链接的架构 (i386))
                <legend id='hAZgN'><style id='hAZgN'><dir id='hAZgN'><q id='hAZgN'></q></dir></style></legend>
                  • <bdo id='hAZgN'></bdo><ul id='hAZgN'></ul>

                    <small id='hAZgN'></small><noframes id='hAZgN'>

                  • <tfoot id='hAZgN'></tfoot>
                      <tbody id='hAZgN'></tbody>

                      <i id='hAZgN'><tr id='hAZgN'><dt id='hAZgN'><q id='hAZgN'><span id='hAZgN'><b id='hAZgN'><form id='hAZgN'><ins id='hAZgN'></ins><ul id='hAZgN'></ul><sub id='hAZgN'></sub></form><legend id='hAZgN'></legend><bdo id='hAZgN'><pre id='hAZgN'><center id='hAZgN'></center></pre></bdo></b><th id='hAZgN'></th></span></q></dt></tr></i><div id='hAZgN'><tfoot id='hAZgN'></tfoot><dl id='hAZgN'><fieldset id='hAZgN'></fieldset></dl></div>