【问题标题】:How to get a particular value from a Url in iOS - Swift 3如何从 iOS 中的 Url 获取特定值 - Swift 3
【发布时间】:2017-06-04 20:49:04
【问题描述】:

我有一个附有注册码的网址。我只想从下面的 url 检索注册码 7954741093-41547468-3

https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04

【问题讨论】:

  • 那么这里的问题是什么?你试过什么了?听说过正则表达式吗?

标签: ios swift string url swift3


【解决方案1】:

你可以用这个:

let regCode:String = (url.components(separatedBy: "/").last?.components(separatedBy: "?").first)!

网址在哪里

let url:String = "https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04"

【讨论】:

    【解决方案2】:

    我认为使用URLComponents 更健壮一些:

    let url = "https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04"
    let components = URLComponents(string: url)
    components?.path.components(separatedBy: "/").last
    

    【讨论】:

      猜你喜欢
      • 2022-06-28
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      相关资源
      最近更新 更多