Author Topic: STRREVERSE  (Read 983 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
STRREVERSE
« on: May 02, 2018, 09:23:07 PM »
Code: OxygenBasic
  1. function StrReverse(string s) as string
  2. =======================================
  3. int le=len s
  4. int j=le
  5. int i
  6. string t=nuls le
  7. byte bs at strptr s
  8. byte bt at strptr t
  9. indexbase 1
  10. for i=1 to le
  11.   bt[j]=bs[i]
  12.   j--
  13. next
  14. return t
  15. end function
  16. '
  17. 'TEST:
  18. ======
  19. print StrReverse "1234ABCD"
  20.  

Code: Script BASIC
  1. OPEN "warpeace.txt" FOR INPUT AS 1
  2. flen = FILELEN("warpeace.txt")
  3. fstr = INPUT(flen, 1)
  4. rev = STRREVERSE(fstr)
  5. PRINT LEFT(rev,500),"\n"
  6.  


jrs@jrs-laptop:~/sb/examples/test$ time scriba strrev.sb

.suoicsnoc ton era ew hcihw
fo ecnedneped a ezingocer ot dna ,tsixe ton seod taht modeerf a
ecnuoner ot yrassecen ylralimis si ti esac tneserp eht ni ;leef ton
did ew noitom a ezingocer ot dna ecaps ni ytilibommi laernu na fo
ssensuoicsnoc eht ecnuoner ot yrassecen saw ti esac tsrif eht nI

".swal ta evirra ew ,esuac no dna ,emit no ,dlrow
lanretxe eht no ecnedneped ruo gnittimda yb elihw ,ytidrusba ta evirra
ew lliw eerf ruo gnittimda yb tub ,ecnedneped ruo fo suoicsnoc
ton era ew taht eurt si

real   0m0.089s
user   0m0.060s
sys   0m0.000s
jrs@jrs-laptop:~/sb/examples/test$