-
Will this code also pick up punuation in a palindrome sentence? Could If go in place of the While?
Dim intPosition As Integer
Dim strText As String
Dim strResult As String
strText = txtInput.Text
While intPosition =< Len(strText)
intPosition = intPosition + 1
strResult = Mid(strText, intPosition, 1) & strResult
Wend
If strResult = strText Then
MsgBox "The string is a palindrome!"
End If
-
That routine will pick up all characters contained in the string passed to it, punctuation and all.
You could also replace the While loop with the strReverse function.
From MSDN:
Dim MyStr
MyStr = StrReverse("VBScript") ' MyStr contains "tpircSBV".
-
tappling:
Why are you starting a new thread for each post you want to post under the same topic?
-
I thought so but my instructor wanted us to use an IF statement. I just wanted to be sure so if I changed the While to If would it change the program?
-
Yes it would.
The code I posted:
Code:
Dim intPosition As Integer
Dim strText As String
Dim strResult As String
strText = txtInput.Text
While intPosition =< Len(strText)
intPosition = intPosition + 1
strResult = Mid(strText, intPosition, 1) & strResult
Wend
If strResult = strText Then
MsgBox "The string is a palindrome!"
End If
This code does have an If statement. Just look at the last three lines.
-