1、ff = "aabbbaaaabababbabbbbbbabbaab"
For i = 1 To 2
If i = 1 Then
pd = "a"
Else
pd = "b"
End If
pds = 0
For j = 1 To Len(ff)
ty = Mid(ff, j, 1)
If ty = pd Then
pds = pds + 1
Else
tt = "insert into js(ZF,ZFS) values(" & """" & pd & """" & "," & pds & ")"
If pds >= 2 Then
'MsgBox tt & pds
CurrentDb.Execute (tt)
End If
pds = 0
End If
Next
Next
Set QQRR = CurrentDb.OpenRecordset("SELECT ZF,MAX(ZFS) FROM JS GROUP BY ZF")
Do While Not QQRR.EOF
MsgBox QQRR(0) & QQRR(1)
QQRR.MoveNext
Loop
str="aabbbaaaabababbabbbbbbabbaab"
strA=""
strB=""
strC=""
j=Mid(str,1,1)
for i=1 to Len(str)
if Mid(str,i,1)<>j then
if j="a" then
if Len(strC)>Len(strA) then
strA=strC
strC=""
strC=mdi(str,i,1)
j=mdi(str,i,1)
end if
else
if len(strC)>len(strB) then
strB=strC
strC=""
strC=mdi(str,i,1)
j=mdi(str,i,1)
end if
end if
else
strC=strC & mdi(str,i,1)
j=mdi(str,i,1)
End if
next i
str="aabbbaaaabababbabbbbbbabbaab"
strA=""
strB=""
strC=""
j=Mid(str,1,1)
for i=1 to Len(str)
if Mid(str,i,1)<>j then
if j="a" then
if Len(strC)>Len(strA) then
strA=strC
end if
else
if len(strC)>len(strB) then
strB=strC
end if
end if
strC=""
strC=mdi(str,i,1)
j=mdi(str,i,1)
else
strC=strC & mdi(str,i,1)
j=mdi(str,i,1)
End if
next i
Private Sub Command0_Click()
Dim str As String
Dim strA As String
Dim strB As String
Dim strC As String
Dim i As Integer
Dim j As String
str = "aabbbaaaabababbabbbbbbabbaabaaaaaaaa"
strA = ""
strB = ""
strC = ""
j = Mid(str, 1, 1)
For i = 1 To Len(str)
If Mid(str, i, 1) <> j Then
If j = "a" Then
If Len(strC) > Len(strA) Then
strA = strC
End If
Else
If Len(strC) > Len(strB) Then
strB = strC
End If
End If
strC = ""
strC = Mid(str, i, 1)
j = Mid(str, i, 1)
Else
strC = strC & Mid(str, i, 1)
j = Mid(str, i, 1)
End If
Next i
If j = "a" Then
If Len(strC) > Len(strA) Then
strA = strC
End If
Else
If Len(strC) > Len(strB) Then
strB = strC
End If
End If
MsgBox "a最长的是'" & strA & "'"
MsgBox "b最长的是'" & strB & "'"
End Sub
Function mx(zfc As String, fgf As String) As Integer
Dim i As Integer
Dim n As Integer
n = UBound(Split(zfc, fgf))
mx = Len(Split(zfc, fgf)(0))
For i = 0 To n
If mx < Len(Split(zfc, fgf)(i)) Then mx = Len(Split(zfc, fgf)(i))
Next i
End Function
调用:
maxa = mx("aabbbaaaabababbabbbbbbabbaab", "b"): MsgBox maxa & "连a"
maxb = mx("aabbbaaaabababbabbbbbbabbaab", "a"): MsgBox maxb & "连b"
ff = "aabbbaaaabababbabbbbbbabbaab"
For i = 1 To 2
rt = Split(ff, IIf(i = 1, "a", "b"))
For i1 = LBound(rt) To UBound(rt) - 1
For j = i1 + 1 To UBound(rt)
If rt(i1) < rt(j) Then
ty = rt(i1)
rt(i1) = rt(j)
rt(j) = ty
End If
Next
Next
MsgBox rt(0)
Next
以下是引用wwwwa在2006-8-29 15:56:00的发言:
ff = "aabbbaaaabababbabbbbbbabbaab"
For i = 1 To 2
rt = Split(ff, IIf(i = 1, "a", "b"))
For i1 = LBound(rt) To UBound(rt) - 1
For j = i1 + 1 To UBound(rt)
If rt(i1) < rt(j) Then
ty = rt(i1)
rt(i1) = rt(j)
rt(j) = ty
End If
Next
Next
MsgBox rt(0)
Next