<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getWeatherbyCityNameResponse xmlns="http://tempuri.org/"><getWeatherbyCityNameResult><string xsi:nil="true"/><string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif</string><string xsi:nil="true"/></getWeatherbyCityNameResult></getWeatherbyCityNameResponse></soap:Body></soap:Envelope>有点象XML的,不知是不是,要取出下面的内容:齐齐哈尔
晴
6 ~ -2 ℃
西北风3-4级转微风
今天
http://www.ayandy.com/images/晴.gif该如何做?
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getWeatherbyCityNameResponse xmlns="http://tempuri.org/"><getWeatherbyCityNameResult><string xsi:nil="true"/><string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif</string><string xsi:nil="true"/></getWeatherbyCityNameResult></getWeatherbyCityNameResponse></soap:Body></soap:Envelope>有点象XML的,不知是不是,要取出下面的内容:齐齐哈尔
晴
6 ~ -2 ℃
西北风3-4级转微风
今天
http://www.ayandy.com/images/晴.gif该如何做?
解决方案 »
- 关于向SSTab控件Tab添加控件。
- 怎样屏蔽outlook的安全提示!
- 关于vb使用winsock控件开发服务器端和多客户端的几个疑问,高手进来一下
- 无法修改datagrid表格中的内容,紧急求助!!
- VB编译好后,运行环境是什么?一定要安装VB吗?
- 【CSDN】【如何根据MSFlexGrid控件中内容的字符长度自动调整列宽,保证所有字符可见】
- 临时表怪问题!!
- VB对word表格的操作。。。。[很急!!!]
- Visual Basic能不能用代码在Form中添加一个按钮对象,或者picturebox对象?
- 如何这样通讯???
- 请问谁有斗地主和麻将的源码或算法呀,~~人机对战的~
- 做IC卡读写程序该从何下手
'发现你想要的内容都在<string></string>对中
'思路:1.取出第一个<string> 及其之后的内容
' 得到 <string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif</string><string xsi:nil="true"/></getWeatherbyCityNameResult></getWeatherbyCityNameResponse></soap:Body></soap:Envelope>
' 2.取出最后一个 </string> 之前的内容,不含 最后一个 </string>
' 得到 <string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif
' 3.去除 所有的 <string>,
' 得到 齐齐哈尔</string>晴</string>6 ~ -2 ℃</string>西北风3-4级转微风</string>今天</string>http://www.ayandy.com/images/晴.gif
' 4.将字符串以 </string> 为分隔符 放入数组
' 得到结果
Dim s As String
Dim i As Integer
'给 s 赋值你的内容
'由于字符串中包含双引号 (") 输起来麻烦,用单引号代替
s = "<?xml version='1.0'?>" & _
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><getWeatherbyCityNameResponse xmlns='http://tempuri.org/'><getWeatherbyCityNameResult><string xsi:nil='true'/><string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif</string><string xsi:nil='true'/></getWeatherbyCityNameResult></getWeatherbyCityNameResponse></soap:Body></soap:Envelope>"
'替换 单引号为 双引号,
'此处不作替换也不影响结果
s = Replace(s, "'", Chr(34))
'取第一个<string> 的位置
i = InStr(s, "<string>")
'取第一个<string> 及其 后的所有内容
s = Mid(s, i)
'取最后一个 </string> 的内容
i = InStrRev(s, "</string>")
'取最后一个 </string> 之前的内容,不含最后一个 </string>
s = Left(s, i - 1)
'去除 <string>
s = Replace(s, "<string>", "")
Dim strValue() As String
'将每一项的内容放入数组中
strValue = Split(s, "</string>")
'取每一项的内容
For i = 0 To UBound(strValue)
Debug.Print strValue(i)
Next
用正则表达式,很容易做到工程-引用
Microsoft VBScript Regular Expressions 5.5建一个text1.text和text2.text,Command1控件Private Sub Command1_Click()
Dim a As Stringa = Replacex(Text1.Text, "</string>", vbNewLine)Text2.Text = Replacex(a, "<(.*?)>", "")End Sub
Private Function Replacex(sourceStr As String, oldStr As _
String, newStr As String, Optional ignoreCase As Boolean, Optional isGlobal As Boolean = True)
Dim re As New RegExp
re.Pattern = oldStr
re.Global = isGlobal
re.ignoreCase = False
Replacex = re.Replace(sourceStr, newStr)
Set re = Nothing
End Function
text2.text就是你想要的
齐齐哈尔,晴,6 ~ -2 ℃,西北风3-4级转微风,今天,http://www.ayandy.com/images/晴.gif这该如何做?
a = Replacex(Text1.Text, "</string>", vbNewLine)这一句
把这个标签替换成换行了
你想要,这个符号,就把vbnewline换成,就行了:
a = Replacex(Text1.Text, "</string>", ",")
就这样
工程-引用
Microsoft VBScript Regular Expressions 5.5建一个text1.text和text2.text,Command1控件Private Sub Command1_Click()
Dim a As Stringa = Replacex(Text1.Text, "</string>", ",")Text2.Text = Replacex(a, "<(.*?)>", "")End Sub
Private Function Replacex(sourceStr As String, oldStr As _
String, newStr As String, Optional ignoreCase As Boolean, Optional isGlobal As Boolean = True)
Dim re As New RegExp
re.Pattern = oldStr
re.Global = isGlobal
re.ignoreCase = False
Replacex = re.Replace(sourceStr, newStr)
Set re = Nothing
End Function