Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reversing a Variable?

Status
Not open for further replies.

Joker21

Programmer
Oct 9, 2002
1
US
Could anyone please help me with a code that could reverse a variable?
For instance how do I get:
A = Hello World
To equal this:
B = dlroW olleH

For the Program I'm writing, I need to be able to check for Palindromes. (i.e. ABBA, DAD, MOM, 12233221, ect.) The only way I can figure to do this is to divide the variable in half, reverse the second half and check to see if the first half and second half are equal. I've figured out most of the code, but I cannot figure out how to reverse the second half of the variable. Any Help would be appreciated.

j0ker
 
Something like...
Code:
A$ = "Hello there"
FOR Rep = LEN(A$) TO 1 STEP -1
    B$ = B$ + MID$(A$, Rep, 1)
NEXT
PRINT B$

VCA.gif
 
Oops.... missed part of your question.
Code:
A$ = "Hello olleH"
FOR Rep = LEN(A$) \ 2 TO 1 STEP -1
    B$ = MID$(A$, Rep, 1) + B$
NEXT
IF B$ <> LEFT$(A$, LEN(A$) \ 2) THEN
    PRINT &quot;Not a palindrome.&quot;
END IF

VCA.gif
 
a$=&quot;This routine should be faster as it does'nt redimension strings in the loop&quot;

b$=a$
c$=&quot; &quot;:d% =len(a$)+1
for i%=1 to len(a$)\2
lset c$=mid$(b$,i%,1)
mid$(b$,i%,1)=mid$(b$,d%-i%,1)
mid$(b$,d%-i%,1)=c$
next
print a$,b$

sleep

Antoni
 
Speed is such a pressing issue for P4's with 256 megs DDR running 16 bit DOS instructions with disk caching.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top