<?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该如何做?

解决方案 »

  1.   

    '分析你的文字
        '发现你想要的内容都在<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
      

  2.   

    还是过滤html标签的问题,我早上花了20Q币+100分求来的,5555555555~~~~
    用正则表达式,很容易做到工程-引用
    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
      

  3.   

    补充上面的,text1.text放入你发出来的文字
    text2.text就是你想要的
      

  4.   

    to :zhaoyifhq() ( )谢谢了,不过偶对正则不了解,能否再请教一下?如我要在相关内容插入某些字符,以方便其他程序分割使用,该如何做?插入如下:
    齐齐哈尔,晴,6 ~ -2 ℃,西北风3-4级转微风,今天,http://www.ayandy.com/images/晴.gif这该如何做?
      

  5.   

    ><string>齐齐哈尔</string><string>晴</string><string>6 ~ -2 ℃</string><string>西北风3-4级转微风</string><string>今天</string><string>http://www.ayandy.com/images/晴.gif</string>看你的代码里有</string>这个标签,我上面是用
    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