gpt4 book ai didi

xml - 如何将 XML 中的特殊字符转换为 VBA 中的可读字符串?

转载 作者:行者123 更新时间:2023-12-04 20:14:25 31 4
gpt4 key购买 nike

我有以下代码,它 ping 雅虎财经,并下载特定证券/股票的配置文件:

Public Function getETFDetails(theSymbol As String)
Dim xmlhttp As Object
Dim strURL As String
Dim x As String
Dim sSearch As String, myDIV As String, theDeets As String
'theSymbol = "SPY"

strURL = "http://finance.yahoo.com/q/pr?s=" & theSymbol & "+Profile"
DeleteUrlCacheEntry (strURL)
Set xmlhttp = CreateObject("msxml2.xmlhttp")
With xmlhttp
.Open "get", strURL, False
.send
x = .responsetext
End With
Set xmlhttp = Nothing

sSearch = "Fund Summary"
myDIV = Mid(x, InStr(1, x, sSearch) + Len(sSearch))
sSearch = "<td>"
myDIV = Mid(myDIV, InStr(1, myDIV, sSearch) + Len(sSearch))
theDeets = Left(myDIV, InStr(1, myDIV, "</td>") - 1)

getETFDetails = theDeets

End Function

这很好用,我得到了很好的结果。但是,如果结果包含特殊字符(例如,S&P500 ETF,'SPY'),我会得到以下信息:
The investment seeks to provide investment results that, before expenses, 
generally correspond to the price and yield performance of the S&amp;P 500® Index.

符号和商标的处理是我的问题。我如何让他们脱离结果?我可以完全删除它们并让它说“SP 500”,但我希望有更强大的东西,然后通过一些字符列表(字符串)手动删除它们。有什么想法吗? (我尝试过使用 StrConv 函数,但无论出于何种原因,它只返回字符串的第一个字符。)

最佳答案

VBA 中没有内置的“HTML/XML 解码”功能,但您可以将字符串写入 XML 文档并读回文本。例如:

Set doc = CreateObject("Msxml2.DOMDocument.6.0")
strXML = "S&amp;P 500"
doc.LoadXML "<root>" & strXML & "</root>"
strDecoded = doc.Text

关于xml - 如何将 XML 中的特殊字符转换为 VBA 中的可读字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31328863/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com