【问题标题】:I need to save an url parameter with Swift我需要用 Swift 保存一个 url 参数
【发布时间】:2017-02-04 20:20:06
【问题描述】:
我有一个这样的网址:
let myURL = http://localhost/#access_token=12312312.1231231.31321
我需要从该 URL 中获取“12312312.1231231.31321”。我已经尝试过 componentsSeparatedByString 但我没有得到我需要的东西。
【问题讨论】:
标签:
swift
url
nsstring
nsurl
url-parameters
【解决方案1】:
看看你的问题,这正是你使用componentsSeparatedByString提到的内容
let myURL = "http://localhost/#access_token=12312312.1231231.31321"
let strings = myURL.components(separatedBy: "=")
print(strings[1]) //strings[1] will give you the "12312312.1231231.31321"
componentsSeparatedByString 在这种情况下会返回一个由"=" 分隔的字符串数组。