Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I need help reversing a string
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Valderino




PostPosted: 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
Sponsor
sponsor
Lucas




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Turing:
put name (a) ..
Lucas




PostPosted: 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




PostPosted: 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




PostPosted: 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? Razz
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: