Function StrReplace(s As String, p As String, r As String) As String
Dim re As RegExp
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = p
StrReplace = CStr(re.Replace(s, r))
End Function
Private Sub Command1_Click()
Dim p As String
Dim s As String
s = "aabc1234,dsss12cm 1223dddd.AAAA1111 '''ffgfhjkl"
p = "[A-Za-z0-9]{7}"
s = StrReplace(s, p, "")
p = "[^A-Za-z0-9]+"
s = StrReplace(s, p, ",")
Debug.Print s
dim str as string '类似aabc1234,dsss12cm 1223dddd..AAAA1111'''ffgfhjkl的字符串(不能超过256个)
dim s as string,Mystr as string
dim i as integer
str="aabc1234,dsss12cm 1223dddd..AAAA1111'''ffgfhjkl"
’判断是否为字母的函数
Private Function IsLeter(c As String) As Boolean
Dim asci As Byte
IsLeter = False
asci = Asc(c)
If (asci >= Asc("A") And asci <= Asc("Z")) Or (asci >= Asc("a") And asci <= Asc("z")) Then
IsLeter=true
End Function
'将中间的所有数字和字母取出来形成新的字符串:Mystr=aabc1234dsss12cm1223ddddAAAA1111ffgfhjkl
for i=1 to len(str)
s=mid(str,i,1)
if IsNumeric(s) or IsLeter(s) then
Mystr=Mystr & s
endif
next
'然后按要求提取出来
for i=8 to len(str) step 8
s=mid(Mystr,i,1)&","
next
dim tStr,aStr,bStr,cStr as string
dim Strno%
tStr="abc1234,dsss12cm,1223dddd AAAA1111.............."
bStr=""
for Strno%=0 to xx(字符串组数)
aStr=mid(tStr,1+Strno%*8,8)
if trim(aStr)="" then exit for
cStr=mid(aStr,7,1)
if bStr="" then
bStr= cStr
else
bStr= bStr & "," & cStr
endif
next Strno%