![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Nice work. Keep pluggin', mate.
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
What does it do? Trim the string?
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
looking good, i started learning Ruby too, it is a bit pythonlike so it is cool.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|