vb提取文本文件中的特定数据,然后存入listview
文本文件如下:IP地址用户名密码[222.222.222.222]:admin[空][222.22.222.2]:administrator[空][222.222.222...
文本文件如下:
IP地址 用户名 密码
[222.222.222.222]: admin [空]
[222.22.222.2 ]: administrator [空]
[222.222.222.2 ]: admin [空]
[222.222.222.22 ]: admin [123456]
[222.222.222.222]: admin [123]
[222.22.222.2 ]: administrator [空]
我想把[]的IP地址提取出来存入变量ip
然后是用户名提取出来admin
再是把密码从第二个[]中拿出来存入变量pass
然后依次存入listview控件
1楼和2楼的 代码都不行 luckywhale 你的代码不可行 展开
IP地址 用户名 密码
[222.222.222.222]: admin [空]
[222.22.222.2 ]: administrator [空]
[222.222.222.2 ]: admin [空]
[222.222.222.22 ]: admin [123456]
[222.222.222.222]: admin [123]
[222.22.222.2 ]: administrator [空]
我想把[]的IP地址提取出来存入变量ip
然后是用户名提取出来admin
再是把密码从第二个[]中拿出来存入变量pass
然后依次存入listview控件
1楼和2楼的 代码都不行 luckywhale 你的代码不可行 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim IP() As String, Admin() As String, Pass() As String
Dim IPS() As String, j%, I%
Dim IPADPAS As String, AdminPass() As String
I = GetTxtCount(App.Path & "\IP.txt")
ReDim IP(1 To I), Admin(1 To I), Pass(1 To I)
Open App.Path & "\IP.txt" For Input As #1
Do While Not EOF(1)
j = j + 1
Line Input #1, IPADPAS
If IPADPAS <> "" Then
IPS = Split(IPADPAS, ":")
IP(j) = Right((Left(IPS(0), Len(IPS(0)) - 1)), Len(IPS(0)) - 2)
AdminPass = Split(Trim(IPS(1)), " ")
Admin(j) = AdminPass(0)
Pass(j) = IIf(Left(AdminPass(1), 1) = "[", "", AdminPass(1))
End If
Loop
Close #1
For I = 1 To I
List1.AddItem IP(I) & "," & Admin(I) & "," & Pass(I)
Next I
End Sub
Private Function GetTxtCount(sPath As String) As Long
Dim I As Long, V As String
Open sPath For Input As #1
While Not EOF(1)
Line Input #1, V
If V <> "" Then I = I + 1
Wend
Close #1
GetTxtCount = I
End Function
Dim IP() As String, Admin() As String, Pass() As String
Dim IPS() As String, j%, I%
Dim IPADPAS As String, AdminPass() As String
I = GetTxtCount(App.Path & "\IP.txt")
ReDim IP(1 To I), Admin(1 To I), Pass(1 To I)
Open App.Path & "\IP.txt" For Input As #1
Do While Not EOF(1)
j = j + 1
Line Input #1, IPADPAS
If IPADPAS <> "" Then
IPS = Split(IPADPAS, ":")
IP(j) = Right((Left(IPS(0), Len(IPS(0)) - 1)), Len(IPS(0)) - 2)
AdminPass = Split(Trim(IPS(1)), " ")
Admin(j) = AdminPass(0)
Pass(j) = IIf(Left(AdminPass(1), 1) = "[", "", AdminPass(1))
End If
Loop
Close #1
For I = 1 To I
List1.AddItem IP(I) & "," & Admin(I) & "," & Pass(I)
Next I
End Sub
Private Function GetTxtCount(sPath As String) As Long
Dim I As Long, V As String
Open sPath For Input As #1
While Not EOF(1)
Line Input #1, V
If V <> "" Then I = I + 1
Wend
Close #1
GetTxtCount = I
End Function
展开全部
Windows.Forms.Cursor.Current = Cursors.WaitCursor
Dim Reader As New IO.StreamReader("文件路径", System.Text.UnicodeEncoding.GetEncoding("gb2312"))
Dim sLine As String = Reader.ReadLine()
Dim a(), b(), ip
Dim u As String = "[1111]"
a = u.Split("[")
b = a(1).split("]")
While Not (sLine Is Nothing)
a = Split(sLine, "[")
b = Split(a(1), "]")
ip = b(0)
End While
你试下我就不全写了
Dim Reader As New IO.StreamReader("文件路径", System.Text.UnicodeEncoding.GetEncoding("gb2312"))
Dim sLine As String = Reader.ReadLine()
Dim a(), b(), ip
Dim u As String = "[1111]"
a = u.Split("[")
b = a(1).split("]")
While Not (sLine Is Nothing)
a = Split(sLine, "[")
b = Split(a(1), "]")
ip = b(0)
End While
你试下我就不全写了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim Str As String
Dim i As Integer
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim IP(20) As String '具体看你有多少个
Dim Acc(20) As String
Dim Pss(20) As String
Open XXXX For Input As #1
Do While Not EOF(1)
Line Input #1, Str '读进一行
A = InStr(Str, "]") '第一个"]"的位置(第一个"["的位置是1)
B = InStr(A + 1, Str, "[") '第二个"["的位置
C = InStr(A + 1, Str, "]") '第二个"]"的位置
IP(i) = Trim(Mid(Str, 2, A - 2)) '第一个[]之间的string去掉前后空格
Acc(i) = Trim(Mid(Str, A + 2, B - A - 2))':[之间的
Pss(i) = Trim(Mid(Str, B + 1, C - B - 1))'第二个[]之间的
i=i+1
Loop
Close
然后加进listview就行了
Dim i As Integer
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim IP(20) As String '具体看你有多少个
Dim Acc(20) As String
Dim Pss(20) As String
Open XXXX For Input As #1
Do While Not EOF(1)
Line Input #1, Str '读进一行
A = InStr(Str, "]") '第一个"]"的位置(第一个"["的位置是1)
B = InStr(A + 1, Str, "[") '第二个"["的位置
C = InStr(A + 1, Str, "]") '第二个"]"的位置
IP(i) = Trim(Mid(Str, 2, A - 2)) '第一个[]之间的string去掉前后空格
Acc(i) = Trim(Mid(Str, A + 2, B - A - 2))':[之间的
Pss(i) = Trim(Mid(Str, B + 1, C - B - 1))'第二个[]之间的
i=i+1
Loop
Close
然后加进listview就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询