Reputation: 39374
I have a url that is reg code attached to it. I just want to retrieve the reg code 7954741093-41547468-3 from the below url
https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04
Upvotes: 1
Views: 546
Reputation: 14030
i think using URLComponents
is a little more robust:
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
Upvotes: 0
Reputation: 3854
You can use this:
let regCode:String = (url.components(separatedBy: "/").last?.components(separatedBy: "?").first)!
Where url is
let url:String = "https://mycode.funny.net/mycode/Registrations/7954741093-41547468-3?api-version=2011-04"
Upvotes: 1