VB怎么只读取字符串中的数字部分
答案:1 悬赏:60 手机版
解决时间 2021-03-19 08:26
- 提问者网友:轻浮
- 2021-03-18 12:40
VB怎么只读取字符串中的数字部分
最佳答案
- 五星知识达人网友:北城痞子
- 2021-03-18 13:53
字符串中提取数字的代码
Private Sub Command1_Click()
Dim s As String, k As Integer, c() As String
Dim p As String, i As Integer
s = Text1.Text
k = 1
For i = 1 To Len(s)
If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then
p = p & Mid(s, i, 1)
ElseIf Mid(s, i + 1, 1) >= "0" And Mid(s, i + 1, 1) <= "9" And i <> 1 Then
If p <> "" Then
ReDim Preserve c(k)
c(k) = p
k = k + 1
p = ""
End If
End If
Next i
ReDim Preserve c(k)
c(k) = p
For i = 1 To k
List1.AddItem (c(i))
Next i
End Sub
Private Sub Form_Load()
Text1.Text = "abc123d4fr567yh89l09df4m67dkj21"
End Sub
Private Sub Command1_Click()
Dim s As String, k As Integer, c() As String
Dim p As String, i As Integer
s = Text1.Text
k = 1
For i = 1 To Len(s)
If Mid(s, i, 1) >= "0" And Mid(s, i, 1) <= "9" Then
p = p & Mid(s, i, 1)
ElseIf Mid(s, i + 1, 1) >= "0" And Mid(s, i + 1, 1) <= "9" And i <> 1 Then
If p <> "" Then
ReDim Preserve c(k)
c(k) = p
k = k + 1
p = ""
End If
End If
Next i
ReDim Preserve c(k)
c(k) = p
For i = 1 To k
List1.AddItem (c(i))
Next i
End Sub
Private Sub Form_Load()
Text1.Text = "abc123d4fr567yh89l09df4m67dkj21"
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯