急。。。来个活人。。。
从字符串中不断读入字符,遇到空格后,将空格前的子串取出逆序连接,如果和原字串一致则给统计回文串个数的计数器加1;重复此操作直至字符串处理完毕,通过MsgBox函数给出统计结果。
Private Sub Form_Click()
Dim s As String
Dim fj() As String
Dim i As Long, j As Long
Dim t As String, k As Long
s = InputBox("请输入需要统计的字符串")
If Len(s) > 0 Then
fj = Split(s, " ")
For i = 0 To UBound(fj)
If Len(fj(i)) > 0 Then
t = ""
For j = 1 To Len(fj(i))
t = Mid(fj(i), j, 1) & t
Next j
If fj(i) = t Then k = k + 1
'Debug 开始
Print fj(i), t, k
'Debug 结束
End If
Next i
MsgBox "总输入字符串:" & UBound(fj) & " 条,共有 " & k & " 条回文串。"
End If
End Sub