【发布时间】:2017-10-14 21:41:51
【问题描述】:
我正在使用 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]
}
}
谢谢。
【问题讨论】:
-
你用谷歌搜索过
substring(with:)' is deprecated: Please use String slicing subscript吗?那里似乎有很多 -
是的,我偏离了方向搜索。但我没有找到适合我的答案。而且我不明白为什么会收到此错误。