Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 18th, 2005, 8:35 PM   #1
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
Ruby Uppercase/Lowercase converter

Just a simple converter to take text and covert it to uppercase or lowercase depending on what the user chooses. Written to help me learn Ruby better.
Enjoy.

#							             		Ruby Tools										                                     	
#This program allows you to do a few things such as convert strings to upper and  	 
#lowercase. Have fun using it!																	 														 		
#Written by: Bulio. 																				 																		 
#						                        ©bulio 2005								                										



puts "Welcome to the multi-purpose program!\n Make a selection now."
puts "1.Convert a string to lowercase\n 2.Convert a string to uppercase"

sel = STDIN.gets.to_i #Gets user input, turns it into an integer.

if sel == 1 #If what they entered was 1, do this.
	puts "Enter your String to be converted now."
	line = STDIN.gets.chomp
	puts "Your string in lowercase: #{line.downcase}" #Use line.downcase to take line and make it all lowercase.
	puts "Hit enter to exit when done"
	gets
	exit() #Exit when user hits enter
	
	
elsif sel == 2
	puts "Enter your string that will be converted now"
	line = STDIN.gets.chomp
	puts "You string in uppercase: #{line.upcase}" #Same as above, only turns it to uppercase
	puts "Hit enter to quit when done"
	gets
	exit()
	
else
	puts "Invalid choice #{sel}. Try again" 
end
bulio is offline   Reply With Quote
Old Aug 19th, 2005, 8:33 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Nice work. Keep pluggin', mate.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Aug 19th, 2005, 8:53 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I love the chomp keyword I've know its not just Ruby oriented... but still like it. lol
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 19th, 2005, 1:27 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
What does it do? Trim the string?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Aug 19th, 2005, 1:30 PM   #5
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
looking good, i started learning Ruby too, it is a bit pythonlike so it is cool.
coldDeath is offline   Reply With Quote
Old Aug 19th, 2005, 3:01 PM   #6
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
Made another version of it, this one has more options and allows you to quit, and return to the main menu.

EDIT: Because of something with sciTE the code's formatting came out a bit loopy.

#Create the main class, where everything will be stored

class Main
	#Creates the program's intro
	def intro
		puts "Welcome to the character conversion program. Written by bulio."
		puts "\n\n 1.Convert a string to lowercase.\n 2.Convert a string to uppercase.\n Type quit to quit.\nMake a selection now"
		end
	#Create our input loops and such
	def input
		while user_input = STDIN.gets.chomp!
		case user_input
			when '1' then puts "Enter the string that will be converted to Lowercase now."
				line = STDIN.gets
				puts "Your string in Lowercase: #{line.downcase}"
			when '2' then puts "Enter the string that you would like to be converted to into Uppercase."
				line = STDIN.gets
				puts "The string in Uppercase: #{line.upcase}"
			when 'quit' 
			puts "Quitting now"
			exit
			else
				puts "Invalid selection #{user_input}"
				intro
				end
			end
		end	
end		

#Create the program
m = Main.new
m.intro
m.input
bulio is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC