我有一個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