Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2011, 10:07 AM
abit2theright abit2theright is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 abit2theright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 37 sec
Reputation Power: 0
Need help with a Ruby assignment

Here is the assignment directions:

In this program you need to create a letter counter. A user is first asked to enter a string. After that, the user is asked to enter a character. The program should count and display the number of times that the specified character appears in the string.

Unfortunately, I do not know where to start if someone could give me a hand?

I would appreciate any help given!

-Max

Reply With Quote
  #2  
Old November 17th, 2011, 04:51 PM
twostepted's Avatar
twostepted twostepted is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: Central Washington (USA)
Posts: 518 twostepted User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 30 m 12 sec
Reputation Power: 10
Send a message via Yahoo to twostepted
I shouldn't be doing your homework for you, but I'm bored and thinking about ruby.
Code:
def run
    puts 'Enter a string to search'
    text = gets.chomp!
    puts 'Enter a character to search for'
    target = gets.chomp!
    count = text.scan(/#{target}/).count
    puts "Found #{count} occurrences of the character #{target}"
end
run

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Need help with a Ruby assignment

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap