VB 怎样提取文本框某个范围的字符?

2024-11-07 11:38:39
推荐回答(2个)
回答1:

用字符串函数

先用split函数把文本框内容根据回车换行分割为多个字符串

然后再用mid函数提取当中的数字

代码如下,

Private Sub Command1_Click()
Dim str() As String
Dim t As String

t = Replace(Text1, Chr(13) & Chr(10), Chr(13))
str = Split(t, Chr(13))

Dim max As Integer
max = UBound(str)
Dim i As Integer
i = 0

Dim result As String
Dim count As Integer
count = 0

Do While i <= max

Dim s As Integer
Dim e As Integer

s = InStr(str(i), "{")
e = InStr(str(i), "块")
If s > 0 And e > s Then
Dim tmp As String
tmp = Mid(str(i), s + 1, e - s - 1)
Dim tmp_number As Integer
tmp_number = CInt(tmp)
If tmp_number >= 178 And tmp_number <= 188 Then
s = InStr(str(i), ":")
e = InStr(str(i), "(")
If s > 0 And e > s Then

tmp = Mid(str(i), s + 1, e - s - 1)
Dim num() As String
num = Split(tmp)
count = count + UBound(num)
result = result & Join(num, ",")
End If
End If

End If

i = i + 1
Loop
MsgBox result & "(" & count & "组)"

End Sub

回答2:

{172块}:???
是啥意思?