我停留在从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。我不想通过字符串提前或索引来完成。我可以通过指定我需要的数字,点(。)和冒号(:)在迅速获得此字符串。我的意思是一些数字和一些特殊字符?
我试图
let stringArray = response.componentsSeparatedByCharactersInSet(
NSCharacterSet.decimalDigitCharacterSet().invertedSet)
let newString = stringArray.joinWithSeparator("")
print("Trimmed\(newString)and count\(newString.characters.count)")
但这显然修剪掉点和结肠过。任何建议朋友?
'让newString = stringArray.joined()' –
@LeoDabus我用OP的代码和可能的,但你当然是正确的 - 不需要类型或不必要的空字符串参数。为了清晰起见,我只是添加了类型 - 我认为这是一个很好的练习。 – Grimxn