现要求根据输入的字符串(长度在1000 以内),全部由数字和字母组成,得到大小写不敏感压缩后的结果(即所有小写字母均视为相应的大写字母)。如:原字符串为aAABBbBCCCaaaaa,压缩后的结果(A,3)(B,4)(C,3)(A,5)。
实现这一功能的程序代码如下:
Private Sub Command1_Click()
Dim s As String, s1 As String
Dim tmp As String, ans As String
Dim i As Integer, j As Integer
s = Text1.Text
s1 = ""
For i = 1 To Len(s)
s1 = s1 & ToUpcase()
Next i
i = 1
Do While i <= Len(s1)
tmp = Mid(s1, i, 1)
ans = ans & "(" & tmp & ","
j = i + 1
Do While j <= Len(s1) And Mid(s1, j, 1) = tmp
j = j + 1
Loop
ans = ans && ")"
Loop
Text2.Text = ans
End Sub
Function ToUpcase(c As String) As String
If c >= "a" And c <= "z" Then
ToUpcase = Chr(Asc(c) - 32)
Else
ToUpcase = c
End If
End Function
在画线处填入适当的语句或表达式,将程序补充完整。