|
-
Sep 27th, 2000, 12:19 PM
#1
Thread Starter
Junior Member
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
-
Sep 27th, 2000, 01:09 PM
#2
Fanatic Member
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".
-
Sep 27th, 2000, 01:15 PM
#3
tappling:
Why are you starting a new thread for each post you want to post under the same topic?
-
Sep 27th, 2000, 01:44 PM
#4
Thread Starter
Junior Member
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?
-
Sep 27th, 2000, 01:56 PM
#5
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.
-
Sep 27th, 2000, 02:01 PM
#6
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|