我有一个url代码附加在它上面。我只是想从以下网址获取REG代码7954741093-41547468-3如何在iOS中从Url获取特定值 - Swift 3
https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04
我有一个url代码附加在它上面。我只是想从以下网址获取REG代码7954741093-41547468-3如何在iOS中从Url获取特定值 - Swift 3
https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04
您可以使用此:
let regCode:String = (url.components(separatedBy: "/").last?.components(separatedBy: "?").first)!
其中URL是
let url:String = "https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04"
感谢兄弟。有效。 – Warrior
我认为使用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
那么这里有什么问题?你试过什么了?曾听说过正则表达式? – LinusGeffarth