vb提取字符串中的数字解决方案
vb提取字符串中的数字
vb中如何实现以下字符串分解
0.3mm
≤123V
5mN
只要数字和小数点~~~~~
------解决方案--------------------
Dim a() As String
Dim acount As Integer
Dim i As Integer
'你的字符串
Dim strX As String
Dim a_num As Boolean
acount = 1
ReDim Preserve a(1 To acount)
For i = 1 To Len(strX)
If (Asc(Mid(strX, i, 1)) > = 48 And Asc(Mid(strX, i, 1)) <= 57) _
Or Asc(Mid(strX, i, 1)) = 46 Then
a(acount) = a(acount) & Mid(strX, i, 1)
If a_num = False Then
a_num = True
End If
Else
If a_num = True Then
acount = acount + 1
ReDim Preserve a(1 To acount)
a_num = False
End If
End If
Next i
那些数字放在a数组,一共acount个
------解决方案--------------------
字符串
qw123jknm234> 2349.23sdf43.43 safjk sadf 1.023,sas
处理结果:
123 234 2349.23 43.43 1.023
------解决方案--------------------
Function MyGet(Srg As String, Optional n As Integer = False, _
Optional start_num As Integer = 1)
Dim i As Integer
Dim s As String
Dim MyString As String
Dim Bol As Boolean
For i = start_num To Len(Srg)
s = Mid(Srg, i, 1)
If n = 1 Then
Bol = Asc(s) < 0 '分離漢字
ElseIf n = 2 Then
Bol = s Like "[a-z,A-Z, ] " '分離字母
ElseIf n = 0 Then
Bol = s Like "# " '分離數字
End If
If Bol Then MyString = MyString & s
Next
MyGet = IIf(n = 1 Or n = 2, MyString, Val(MyString))
End Function
------解决方案--------------------
这样简单点:
i=len(t)
do while i> =1
if (asc(mid(t,i,1)) <asc( "0 ") or asc(mid(t,i,1))> asc( "9 ")) and asc(mid(t,i,1)) <> asc( ". ") then t=replace(t,mid(t,i,1), " ")
i=i-1
loop
vb中如何实现以下字符串分解
0.3mm
≤123V
5mN
只要数字和小数点~~~~~
------解决方案--------------------
Dim a() As String
Dim acount As Integer
Dim i As Integer
'你的字符串
Dim strX As String
Dim a_num As Boolean
acount = 1
ReDim Preserve a(1 To acount)
For i = 1 To Len(strX)
If (Asc(Mid(strX, i, 1)) > = 48 And Asc(Mid(strX, i, 1)) <= 57) _
Or Asc(Mid(strX, i, 1)) = 46 Then
a(acount) = a(acount) & Mid(strX, i, 1)
If a_num = False Then
a_num = True
End If
Else
If a_num = True Then
acount = acount + 1
ReDim Preserve a(1 To acount)
a_num = False
End If
End If
Next i
那些数字放在a数组,一共acount个
------解决方案--------------------
字符串
qw123jknm234> 2349.23sdf43.43 safjk sadf 1.023,sas
处理结果:
123 234 2349.23 43.43 1.023
------解决方案--------------------
Function MyGet(Srg As String, Optional n As Integer = False, _
Optional start_num As Integer = 1)
Dim i As Integer
Dim s As String
Dim MyString As String
Dim Bol As Boolean
For i = start_num To Len(Srg)
s = Mid(Srg, i, 1)
If n = 1 Then
Bol = Asc(s) < 0 '分離漢字
ElseIf n = 2 Then
Bol = s Like "[a-z,A-Z, ] " '分離字母
ElseIf n = 0 Then
Bol = s Like "# " '分離數字
End If
If Bol Then MyString = MyString & s
Next
MyGet = IIf(n = 1 Or n = 2, MyString, Val(MyString))
End Function
------解决方案--------------------
这样简单点:
i=len(t)
do while i> =1
if (asc(mid(t,i,1)) <asc( "0 ") or asc(mid(t,i,1))> asc( "9 ")) and asc(mid(t,i,1)) <> asc( ". ") then t=replace(t,mid(t,i,1), " ")
i=i-1
loop