
-----------------------------------
Valderino
Thu Mar 24, 2011 6:07 pm

I need help reversing a string
-----------------------------------
What is it you are trying to achieve?
I'm trying to reverse a string


What is the problem you are having?
I err... can't do it.

If I have var teststring : string := "testmebro" how do I get put teststring to ouput "orbemtset" 

This is vital to an important conversion program that I have to do. I can get it to convert 222 and other palindromes, but when it tries to convert 2A it gives me the answer for A2 and vice versa.

The sooner I can do this the sooner I can get started on GUI and binary. Any help is incredibly appreciated.

-----------------------------------
Lucas
Thu Mar 24, 2011 6:48 pm

RE:I need help reversing a string
-----------------------------------
reverse for loop saving the individual characters in an array?

-----------------------------------
Lucas
Thu Mar 24, 2011 7:19 pm

RE:I need help reversing a string
-----------------------------------
var name : string := "Lucas"
var backwards : array 1.. length (name) of string

for decreasing a : length (name) .. 1
   backwards (a) := name (a)
   put backwards (a) 
end for

-----------------------------------
Raknarg
Thu Mar 24, 2011 7:34 pm

RE:I need help reversing a string
-----------------------------------
lucas, you could make it even simpler and get rid of the array

var name : string := "Lucas" 

for decreasing a : length (name) .. 1 
put name (a)
end for

-----------------------------------
SNIPERDUDE
Thu Mar 24, 2011 8:34 pm

RE:I need help reversing a string
-----------------------------------
Also, by adding a couple of period characters at the end of the put line, it will keep them all on the same line.
put name (a) ..

-----------------------------------
Lucas
Fri Mar 25, 2011 11:05 am

RE:I need help reversing a string
-----------------------------------
yes, but then its not saved to the computer, its only outputed on the screen

-----------------------------------
SNIPERDUDE
Fri Mar 25, 2011 12:38 pm

RE:I need help reversing a string
-----------------------------------
Wasn't specified. Typically these small programs don't have much of a need to save the text outputted, and just display the text. If saving is going to be included, one could either save the lines into a flexible array and put them in afterwards, or put each line in the text file in the for loop itself.

-----------------------------------
Tony
Fri Mar 25, 2011 12:58 pm

RE:I need help reversing a string
-----------------------------------
Has anyone considered saving it as a new string variable? :P

-----------------------------------
Raknarg
Fri Mar 25, 2011 5:47 pm

RE:I need help reversing a string
-----------------------------------
Yeah, but then again, it wasn't specified.

-----------------------------------
SNIPERDUDE
Fri Mar 25, 2011 6:03 pm

RE:I need help reversing a string
-----------------------------------
var name : string := "Lucas"
var backwards : string := ""

for decreasing i : length (name) .. 1 
    backwards += name(i)
end for

put backwards
