我正在使用html的解码功能.但是我收到了这个警告.我该如何摆脱?
func decode(_ entity : String) -> Character? {
if entity.hasPrefix("&#x") || entity.hasPrefix("&#X"){
return decodeNumeric(entity.substring(with: entity.index(entity.startIndex, offsetBy: 3) ..< entity.index(entity.endIndex, offsetBy: -1)), base: 16)
} else if entity.hasPrefix("&#") {
return decodeNumeric(entity.substring(with: entity.index(entity.startIndex, offsetBy: 2) ..< entity.index(entity.endIndex, offsetBy: -1)), base: 10)
} else {
return characterEntities[entity]
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
rma*_*ddy 21
该someString.substring(with: someRange)只是需要someString[someRange].
所以改变:
entity.substring(with: entity.index(entity.startIndex, offsetBy: 3) ..< entity.index(entity.endIndex, offsetBy: -1))
Run Code Online (Sandbox Code Playgroud)
同
entity[entity.index(entity.startIndex, offsetBy: 3) ..< entity.index(entity.endIndex, offsetBy: -1)]
Run Code Online (Sandbox Code Playgroud)
换句话说,更改.substring(with:为[并将结束更改)为].
结果是Substring,而不是String.因此,您可能需要将结果包装起来String( )以String从子字符串结果中获取a .
| 归档时间: |
|
| 查看次数: |
4063 次 |
| 最近记录: |