我有一文本文件,我要从里面提出所有的IP地址,并且在一个新的文件里输出,每行一个,该怎样写呢?
文本文件如下: 点击 进入 自动代理脚本 配置 210.47.128.67:8080 2015 毫秒 不能连接 
                              不能连接 2005-10-8 18:25:35 
                              点击 进入 自动代理脚本 配置 202.120.142.68:3128 171 毫秒 156 毫秒 
                              不能连接 2005-10-8 18:25:05 
                              点击 进入 自动代理脚本 配置 61.136.84.154:3128 968 毫秒 859 毫秒 
                              不能连接 2005-10-8 18:21:33 
                              点击 进入 自动代理脚本 配置 61.49.34.185:3128 1421 毫秒 140 毫秒 
                              不能连接 2005-10-8 18:21:26 
                              点击 进入 自动代理脚本 配置 202.114.200.115:80 1015 毫秒 不能连接 
                              不能连接 2005-10-8 18:21:01 
                              点击 进入 自动代理脚本 配置 61.131.63.172:8080 3296 毫秒 不能连接 
                              不能连接 2005-10-8 18:19:46

解决方案 »

  1.   

    读取数据啊读到配置开始一直到毫秒结束然后用:string like "*.*.*.*:*"来判断是否是ip
      

  2.   

    假设你读出的一行内容存在STR变量里。i=instr(str,"配置")+2
    str=mid(str,i,instr(i,str,":")-1)
    STR里就是IP地址,不包括端口,如果配置和IP间有空格,那么STR里也会有空格,可以TRIM来去掉。
      

  3.   

    '假设你的文件为"h:\xxx.txt", 输出到"h:\ip.txt"Sub getip(ByVal infile As String, ByRef outfile As String, Optional ByVal includeport As Boolean = False)
    Dim b() As Byte, s() As String, i As LongOpen infile For Binary As #1
    ReDim b(LOF(1))
    Get #1, , b
    Close #1
    s = Split(StrConv(b, vbUnicode), "配置")
    s(0) = "All IP Adress:"
    For i = 1 To UBound(s)
    s(i) = Split(Trim(s(i)), IIf(includeport, " ", ":"))(0)
    Next
    Open outfile For Binary As #1
    Put #1, , Join(s, vbCrLf)
    Close #1Shell "notepad.exe " & outfile, vbNormalFocus
    End SubPrivate Sub Form_load()
    getip "h:\xxx.txt", "h:\ip.txt" ', True
    End Sub
      

  4.   

    用正则表达式Set reg = CreateObject("VBScript.RegExp")
    reg.Pattern = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
    reg.Global = True
    Set matchs = reg.Execute("点202.114.200.115本xxx 202.120.142.68:3128 171 毫y秒u秒")
    For Each x In matchs
    MsgBox x
    Next