Author |
Message |
Valderino
|
Posted: Thu Mar 24, 2011 6:07 pm Post subject: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Lucas
|
Posted: Thu Mar 24, 2011 6:48 pm Post subject: RE:I need help reversing a string |
|
|
reverse for loop saving the individual characters in an array? |
|
|
|
|
|
Lucas
|
Posted: Thu Mar 24, 2011 7:19 pm Post subject: 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
|
Posted: Thu Mar 24, 2011 7:34 pm Post subject: 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
|
Posted: Thu Mar 24, 2011 8:34 pm Post subject: 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.
|
|
|
|
|
|
Lucas
|
Posted: Fri Mar 25, 2011 11:05 am Post subject: RE:I need help reversing a string |
|
|
yes, but then its not saved to the computer, its only outputed on the screen |
|
|
|
|
|
SNIPERDUDE
|
Posted: Fri Mar 25, 2011 12:38 pm Post subject: 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
|
Posted: Fri Mar 25, 2011 12:58 pm Post subject: RE:I need help reversing a string |
|
|
Has anyone considered saving it as a new string variable? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Fri Mar 25, 2011 5:47 pm Post subject: RE:I need help reversing a string |
|
|
Yeah, but then again, it wasn't specified. |
|
|
|
|
|
SNIPERDUDE
|
Posted: Fri Mar 25, 2011 6:03 pm Post subject: RE:I need help reversing a string |
|
|
Turing: | var name : string := "Lucas"
var backwards : string := ""
for decreasing i : length (name ) .. 1
backwards + = name (i )
end for
put backwards |
|
|
|
|
|
|
|