Dha*_*ena 2 xml ios double-quotes swift single-quotes
试图通过xml api发送它的几个特殊字符串.
尝试下面的代码但不适用于所有单引号(')和双引号(")的出现
var strToReturn = "“Hello” ‘world’"
strToReturn = strToReturn.replacingOccurrences(of: "&", with: "&")
strToReturn = strToReturn.replacingOccurrences(of: "<", with: "<")
strToReturn = strToReturn.replacingOccurrences(of: ">", with: ">")
strToReturn = strToReturn.replacingOccurrences(of: "‘", with: "'")
strToReturn = strToReturn.replacingOccurrences(of: "“", with: """)
print("Replaced string : \(strToReturn)")
Run Code Online (Sandbox Code Playgroud)
结果是 "Hello” 'world’
如果有人可以提供帮助,谢谢!
您需要为’和指定替换字符串和”因为’ != ‘和” != “
var strToReturn = "“Hello” ‘world’"
strToReturn = strToReturn.replacingOccurrences(of: "&", with: "&")
strToReturn = strToReturn.replacingOccurrences(of: "<", with: "<")
strToReturn = strToReturn.replacingOccurrences(of: ">", with: ">")
strToReturn = strToReturn.replacingOccurrences(of: "‘", with: "'")
strToReturn = strToReturn.replacingOccurrences(of: "“", with: """)
strToReturn = strToReturn.replacingOccurrences(of: "’", with: "'")
strToReturn = strToReturn.replacingOccurrences(of: "”", with: """)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
732 次 |
| 最近记录: |