VB截取两者之间字符串

2024-11-26 09:45:44
推荐回答(5个)
回答1:

第一步用?拆分,取出参数部分,得到username=张团升含三&password=zhang3&pid=1231234&site=4
第二步用&才分,取出参数集合
数组(username=张三,password=zhang3,pid=1231234,site=4)四个元素
第 三步笑裤,每个元素用=号分隔,就都塌笑取出来了

回答2:

Private Sub Command1_Click()
Dim iStr As String, i As Integer, xx(1 To 4) As String, xx1(1 To 4) As String
xx1(1) = "username": xx1(2) = "password": xx1(3) = "pid"此困卜: xx1(4) = "site"

Open "森穗c:\1.txt" For Input As #1
Open "c:\2.txt" For Output As #2
While Not EOF(1)
Line Input #1, iStr
For i = 1 To 4
xx(i) = find(iStr, xx1(i))
Next
Print #2, Join(xx, ",")
Wend
Close
MsgBox "ok, c:\2.txt"
End Sub

Private Function find(ByVal s As String, ByVal fs As String) As String
Dim k1 As Integer, k2 As Integer, k3 As Integer
k1 = InStr(s, fs)
k2 = InStr(k1, s, "=") + 1 '为防止=号前后有空格的情况,尺销单找=号
k3 = IIf(InStr(k2, s, "&") = 0, Len(s) + 1, InStr(k2, s, "&"))
find = Trim(Mid(s, k2, k3 - k2))

End Function

回答3:

Private Sub Command1_Click()
Dim mArr(), k%, Tmp$, Tmp2, i%, p%
k = 1
ReDim Preserve mArr(1 To 4, 1 To k)
mArr(1, 1) = "用穗蠢户答衫名"
mArr(2, 1) = "密码"
mArr(3, 1) = "PID"
mArr(4, 1) = "Site"
Open "e:\rcd.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Tmp
Tmp2 = Split(Tmp, "=")
k = k + 1
ReDim Preserve mArr(1 To 4, 1 To k)
mArr(1, k) = Replace(Tmp2(1), "&password", "")
mArr(2, k) = Replace(Tmp2(2), "&pid", "")
mArr(3, k) = Replace(Tmp2(3), "猜举陪&site", "")
mArr(4, k) = Tmp2(4)
Loop
Close #1
For p = 1 To k
For i = 1 To 4
Print mArr(i, p),
Next i
Print
Next p
End Sub

回答4:

来灶返个最简单的,操作文者滑件d:\1.txt,输出结果保存在d:\jieguo.txt
Private Sub Command1_Click()
Open "d:\1.txt" For Input As #1
Open "d:\jieguo.txt" For Output As #2
Do Until EOF(1)
Line Input #1, a
t = Split(a, "=")
For i = 1 To 4
p = Split(t(i), "&"首辩腊)
Print #2, p(0) & Space(1);
Next
Print #2,
Loop
Close
Close
End Sub

回答5:

用LEFT(,)或RINGHT(,)语句。