VB查找文本中文字 并取出后面的文字
有一段数据比如:D2010100000000000000F4440C00080129010300000000000000F4440C000801D301040000000...
有一段数据 比如:
D2 01 01 00 00 00 00 00 00 00 F4 44 0C 00 08 01
29 01 03 00 00 00 00 00 00 00 F4 44 0C 00 08 01
D3 01 04 00 00 00 00 00 00 00 F4 44 0C 00 08 01
2A 01 06 00 00 00 00 00 00 00 F4 44 0C 00 08 01
要求取出D3 01后面的一位数据比如上面的04
(04非固定) 展开
D2 01 01 00 00 00 00 00 00 00 F4 44 0C 00 08 01
29 01 03 00 00 00 00 00 00 00 F4 44 0C 00 08 01
D3 01 04 00 00 00 00 00 00 00 F4 44 0C 00 08 01
2A 01 06 00 00 00 00 00 00 00 F4 44 0C 00 08 01
要求取出D3 01后面的一位数据比如上面的04
(04非固定) 展开
3个回答
展开全部
如果是你这种格式的数据,我有一个办法,不知道合不合你的意,:将这段数据存为一个文本文件,比如C:\text.txt 然后用下面的代码得到 D3 01 后面的数据
.
Private Sub Command1_Click()
Dim da As String, da1 As String
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If Left(da, 5) = "D3 01" Then
da1 = Mid(da, 7, 2)
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
.
Private Sub Command1_Click()
Dim da As String, da1 As String
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If Left(da, 5) = "D3 01" Then
da1 = Mid(da, 7, 2)
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面的改进版
Private Sub Command1_Click()
Dim da As String, da1 As String
dim tempstr as string
temp="D3 01"
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If instr(da, temp)Then
da1 = Mid(da,instr(temp)+len(temp)+1 , 2) ‘这里的1是跳过1个空格
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
这样不管你d3 01 在哪都能取后面的2位数据,设temp是方便你改数据
Private Sub Command1_Click()
Dim da As String, da1 As String
dim tempstr as string
temp="D3 01"
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If instr(da, temp)Then
da1 = Mid(da,instr(temp)+len(temp)+1 , 2) ‘这里的1是跳过1个空格
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
这样不管你d3 01 在哪都能取后面的2位数据,设temp是方便你改数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim AR() As String, AR2() As String
sTxt = "2 01 01 00 00 00 00 00 00 00 F4 44 0C 00 08 01 29 01 03 00 00 00 00 00 00 00 F4 44 0C 00 08 01 D3 01 04 00 00 00 00 00 00 00 F4 44 0C 00 08 01 2A 01 06 00 00 00 00 00 00 00 F4 44 0C 00 08 01"
AR = Split(sTxt, "D3 01")
L = LBound(AR) + 1
U = UBound(AR)
For i = L To U
tmp = Trim(AR(i))
AR2 = Split(tmp, " ")
'输出
Me.Print AR2(LBound(AR2)) & Space(2);
Next i
End Sub
Dim AR() As String, AR2() As String
sTxt = "2 01 01 00 00 00 00 00 00 00 F4 44 0C 00 08 01 29 01 03 00 00 00 00 00 00 00 F4 44 0C 00 08 01 D3 01 04 00 00 00 00 00 00 00 F4 44 0C 00 08 01 2A 01 06 00 00 00 00 00 00 00 F4 44 0C 00 08 01"
AR = Split(sTxt, "D3 01")
L = LBound(AR) + 1
U = UBound(AR)
For i = L To U
tmp = Trim(AR(i))
AR2 = Split(tmp, " ")
'输出
Me.Print AR2(LBound(AR2)) & Space(2);
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询