A. vb如何編程
Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim S As String, S1 As String, S2 As String
Dim I As Integer, J As Integer
Dim G As Integer, Hw As Boolean, Find As Boolean
S = Text1.Text
Text1.Text = Text1 + vbCrLf
S1 = S
G = 0
Do While S1 <> ""
Find = False
For I = 1 To Len(S1)
If Mid(S1, I, 1) = " " Or I = Len(S1) Then
Find = True
S2 = Trim(Left(S1, I))
If I = Len(S1) Then S1 = "" Else S1 = Right(S1, Len(S1) - I)
For J = 1 To Len(S2) \ 2
If Mid(S2, J, 1) <> Mid(S2, Len(S2) - J + 1, 1) Then
Hw = False
Exit For
End If
Hw = True
Next
If Hw Then
G = G + 1
Text1.Text = Text1 + " " + S2
End If
End If
If Find Then Exit For
Next
Loop
Text1.Text = Text1.Text + vbCrLf + "共有" + Str(G) + "個迴文串"
End If
End Sub
已經運行過了,沒問題!即使串與串之間多輸入幾個空格也不影響查找!