Showing posts with label Count Letters in a String Using Ruby. Show all posts
Showing posts with label Count Letters in a String Using Ruby. Show all posts

Friday, July 12, 2019

Count Letters in a String Using Ruby

Here is a simple program to ask the user to give a string and then the program will ask the user what letter to be counted in the given string. The program will count the number of occurrence of the given string using Ruby programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com


Sample Program Output


Program Listing

count_letter.rb

# count_letter.rb
# Author   : Jake Rodriguez Pomperada,BSCS,MAED-IT
# Date     : July 9, 2019   Tuesday  12:49 PM
# Address  : Bacolod City, Negros Occidental
# Tools    : Eclipse IDE and Ruby Version 2.6.3
# Location : Bacolod City, Negros Occidental  
# Website  : http://www.jakerpomperada.com
# Emails   : jakerpomperada@gmail.com and jakerpomperada@yahoo.com


loop do
  print "\n\n"
  print "\t===== Count Letters in a String ====="
  print "\n\n"
  print "\tGive a String : "
  str_val = gets.chomp
  print "\n"
  print "\tWhat letter to be count ? : "
  letter_val = gets.chomp

    display = str_val.downcase.count(letter_val)

    display_str = str_val.upcase
    display_letter = letter_val.upcase

    print "\n"
    print "\tThe given string is #{display_str}."
    print "\n\n"
    print "\tThe number of occurrence of the letter" 
    print " #{display_letter} is #{display}."
    puts "\n\n";
    print "\tDo you want to continue? (y/n) : "
    answer = gets.chomp.downcase
    if answer == "n"
   print "\n\n";
      print "\tEnd of Program";
      print "\n\n";
   break
    end
  end