【发布时间】:2017-04-08 07:08:34
【问题描述】:
我一直无法从 html 正文中获取字符串
<html><head>
<title>Uaeexchange Mobile Application</title></head><body>
<div id='ourMessage'>
49.40:51.41:50.41
</div></body></html>
我想获取包含 49.40:51.41:50.41 的字符串。我不想通过字符串提前或索引来做到这一点。我可以通过在swift中指定我只需要数字、点(.)和冒号(:)来获取这个字符串吗?我的意思是一些数字和一些特殊字符?
我试过了
let stringArray = response.componentsSeparatedByCharactersInSet(
NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let newString = stringArray.joinWithSeparator("")
print("Trimmed\(newString)and count\(newString.characters.count)")
但这显然也去掉了点和冒号。朋友们有什么建议吗?
【问题讨论】: