2016-09-27 14 views
-1

我有一个URL是这样的:我需要保存的URL参数与斯威夫特

let myURL = http://localhost/#access_token=12312312.1231231.31321 

我需要“12312312.1231231.31321”从URL。我试过用componentsSeparatedByString,但我没有得到我所需要的。你的问题

+0

让我看看你的代码 –

+2

http://stackoverflow.com/questions/30759158/using-the-split-function-in-swift-2 – Sahil

回答

0

来看,其实只是你使用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将返回由"="在这种情况下,分隔字符串数组有提及。