Private Sub Command2_Click() Dim a As String Dim ls_Content() As String a = "45dgggHBadkdfkAD11" ls_Content = Split(a, "HB")Debug.Print ls_Content(0) Debug.Print ls_Content(1) End Sub
Option Explicit Const SYMBOL As String = "HB" Private Sub Command1_Click() Dim strTest As String Dim strNum1 As String, strNum2 As String Dim nSplit As Integer strTest = "12344HB13354" nSplit = InStr(strTest, SYMBOL) If nSplit > 0 Then strNum1 = Left(strTest, nSplit - 1) strNum2 = Right(strTest, Len(strTest) - nSplit - Len(SYMBOL) + 1) End If Debug.Print strNum1 Debug.Print strNum2 End Sub '本方法可以减少Split函数的出错
a = Split(你的字符串, "HB") For i=0 To UBound(a) msgbox a(i) Next
dim a() as string dim s as string dim i s="123456HB6543221z" a=split(s,"HB") for i=1 to ubound(a)-1 print a(i) next
如果前后的數字位數是固定的也可以用 dim LeftNum as integer,RightNum as integer LeftNum=Left("123HB456",3) RightNum=Right("123HB456",3)
HB是铅笔的硬度参数吗?
HB字符是什么?
如果用它作为分割,那很简单的
用一个FOR就可以搞定了
逐个检验是否是数字,是就保存起来,
不是就前面是一个完整数字字符串,用VAL()还原成数字
后面继续检测,直到是数字,就把从第一个开始用MID()得到后面的数字
EASY
Dim a As String
Dim ls_Content() As String
a = "45dgggHBadkdfkAD11"
ls_Content = Split(a, "HB")Debug.Print ls_Content(0)
Debug.Print ls_Content(1)
End Sub
Const SYMBOL As String = "HB"
Private Sub Command1_Click()
Dim strTest As String
Dim strNum1 As String, strNum2 As String
Dim nSplit As Integer
strTest = "12344HB13354"
nSplit = InStr(strTest, SYMBOL)
If nSplit > 0 Then
strNum1 = Left(strTest, nSplit - 1)
strNum2 = Right(strTest, Len(strTest) - nSplit - Len(SYMBOL) + 1)
End If
Debug.Print strNum1
Debug.Print strNum2
End Sub
'本方法可以减少Split函数的出错
For i=0 To UBound(a)
msgbox a(i)
Next
dim s as string
dim i
s="123456HB6543221z"
a=split(s,"HB")
for i=1 to ubound(a)-1
print a(i)
next
dim LeftNum as integer,RightNum as integer
LeftNum=Left("123HB456",3)
RightNum=Right("123HB456",3)