输入:AAABBAB
输出:A4B3

解决方案 »

  1.   

    Function Check(strVal) As String
        Const cstVal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        Dim intI%
        Dim m, n
        For intI = 0 To Len(cstVal)
            strVal = strVal
            m = Len(strVal)
            strVal = Replace$(strVal, Mid$(cstVal, intI + 1, 1), "")
            n = Len(strVal)
            If m - n <> 0 Then Check = Check & Mid$(cstVal, intI + 1, 1) & (m - n)
        Next
    End Function
      

  2.   

    定义一个整形数组chars[26],把出现的字符次数分别存在对应位置,就可以了
      

  3.   

    Private Type CharType
        Content As String
        RepeatCount As Long
    End Type
    Private Sub Command1_Click()MsgBox CharCount("AAABBAB撒四大四大     阿瑟打死的")
    End SubFunction CharCount(ByVal strVal As String) As String    Dim i As Integer, j As Integer
        Dim strCurrentChar As String
        Dim CharTypeArray() As CharType
        
        Dim ArrayCount As Integer    Dim strRet As String
        
        If Trim(strVal) <> "" Then
            
            For i = 1 To Len(Trim(strVal))
            
                strCurrentChar = Mid(strVal, i, 1)
                
                For j = 1 To ArrayCount
                    If CharTypeArray(j).Content = strCurrentChar Then
                        CharTypeArray(j).RepeatCount = CharTypeArray(j).RepeatCount + 1
                        Exit For
                    End If
                Next
                
                If j > ArrayCount Then
                    ArrayCount = ArrayCount + 1
                    ReDim Preserve CharTypeArray(1 To ArrayCount) As CharType
                    CharTypeArray(ArrayCount).Content = strCurrentChar
                    CharTypeArray(ArrayCount).RepeatCount = 1
                End If
            Next
            
            For i = 1 To ArrayCount
                
                strRet = strRet + CharTypeArray(i).Content & CStr(CharTypeArray(i).RepeatCount)
            Next
            
            CharCount = strRet
            
        Else
            CharCount = ""
        End If
    End Function