Private Sub Command1_Click() Dim AL As String Dim S1$, S2$, S3$, S4$, S5$, S6 As String AL = "BB123FD12KME43413" S1 = Left(AL, 2) S2 = Mid(AL, 3, 2) S3 = Mid(AL, 6, 2) S4 = Mid(AL, 8, 2) S5 = Mid(AL, 10, 3) S6 = Right(AL, 5) Print S1 & " + "; S2 & " + "; S3 & " + "; S4 & " + "; S5 & " + "; S6 End Sub
'--------------------------------------------------------------------------------------- ' 过程名 : RegExpSplit ' 时间 : 2010-3-26 18:18 ' 作者 : 杨过.网狐.cn ' 功能 : http://topic.csdn.net/u/20100326/17/6180058c-c302-4edf-90ea-8f6a23475789.html?61236 ' 说明 : 字符串分离? '--------------------------------------------------------------------------------------- ' Function RegExpSplit() As String Dim regEx, vMatch As Match, Matches ' Create variable. ' Dim RetStr As String, strSubValue As String, strText As String Dim str原文 As String: str原文 = "BB123FD12KME43413" ' Set regEx = New RegExp ' 创建一个RegExp对象,前期绑定,需引用库Microsoft VBScript Regular Expressions 5.5 Set regEx = CreateObject("VBScript.RegExp") '后期绑定 regEx.Pattern = "([A-Z]+)([0-9]+)" ' Set pattern. regEx.IgnoreCase = True ' Set case insensitivity. regEx.Global = True ' Set global applicability. Set Matches = regEx.Execute(str原文) ' Execute search. For Each vMatch In Matches ' Iterate Matches collection. Debug.Print vMatch.SubMatches(0) Debug.Print vMatch.SubMatches(1) NextEnd Function
窗体一个Command1Private Sub Command1_Click() Dim s$, ss$ s = "BB123FD12KME43413" ss = Left(s, 1) For i = 2 To Len(s) If IsNumeric(Mid(s, i - 1, 1)) = IsNumeric(Mid(s, i, 1)) Then ss = ss & Mid(s, i, 1) Else ss = ss & vbCrLf End If Next i MsgBox ss End Sub
刚才没详测,呵呵,修改一下。Private Sub Command1_Click() Dim s$, ss$ s = "BB123FD12KME43413" For i = 1 To Len(s) ss = ss & Mid(s, i, 1) If IsNumeric(Mid(s, i, 1)) <> IsNumeric(Mid(s, i + 1, 1)) Then ss = ss & vbCrLf Next i MsgBox ss End Sub
左 中 右
察看MSDN.
Private Sub Command1_Click()
Dim AL As String
Dim S1$, S2$, S3$, S4$, S5$, S6 As String
AL = "BB123FD12KME43413"
S1 = Left(AL, 2)
S2 = Mid(AL, 3, 2)
S3 = Mid(AL, 6, 2)
S4 = Mid(AL, 8, 2)
S5 = Mid(AL, 10, 3)
S6 = Right(AL, 5)
Print S1 & " + "; S2 & " + "; S3 & " + "; S4 & " + "; S5 & " + "; S6
End Sub
' 过程名 : RegExpSplit
' 时间 : 2010-3-26 18:18
' 作者 : 杨过.网狐.cn
' 功能 : http://topic.csdn.net/u/20100326/17/6180058c-c302-4edf-90ea-8f6a23475789.html?61236
' 说明 : 字符串分离?
'---------------------------------------------------------------------------------------
'
Function RegExpSplit() As String
Dim regEx, vMatch As Match, Matches ' Create variable.
' Dim RetStr As String, strSubValue As String, strText As String
Dim str原文 As String: str原文 = "BB123FD12KME43413"
' Set regEx = New RegExp ' 创建一个RegExp对象,前期绑定,需引用库Microsoft VBScript Regular Expressions 5.5
Set regEx = CreateObject("VBScript.RegExp") '后期绑定 regEx.Pattern = "([A-Z]+)([0-9]+)" ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(str原文) ' Execute search.
For Each vMatch In Matches ' Iterate Matches collection.
Debug.Print vMatch.SubMatches(0)
Debug.Print vMatch.SubMatches(1)
NextEnd Function
Dim s$, ss$
s = "BB123FD12KME43413"
ss = Left(s, 1)
For i = 2 To Len(s)
If IsNumeric(Mid(s, i - 1, 1)) = IsNumeric(Mid(s, i, 1)) Then
ss = ss & Mid(s, i, 1)
Else
ss = ss & vbCrLf
End If
Next i
MsgBox ss
End Sub
Dim s$, ss$
s = "BB123FD12KME43413"
For i = 1 To Len(s)
ss = ss & Mid(s, i, 1)
If IsNumeric(Mid(s, i, 1)) <> IsNumeric(Mid(s, i + 1, 1)) Then ss = ss & vbCrLf
Next i
MsgBox ss
End Sub
(action163) 等 级:
结帖率:103.85% 这是什么情况啊