Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from Gokul595/ruby-programs
Browse files Browse the repository at this point in the history
Ruby program to count the char occurrence in a string.
  • Loading branch information
Gokul595 authored Oct 14, 2018
2 parents 0bb9d5d + 91a2f73 commit 924ce0a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Ruby/count_char.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Returns no. of times the 'char' appears in the 'string'
#
# Note:
# This will behave differently if the value of 'char' is of length more than one.
# Check this link for more info: https://ruby-doc.org/core-2.2.0/String.html#method-i-count
def count_char(string, char)
string.count(char)
end

puts "Enter a string: "
string = gets.chomp
puts "Enter a char to find count: "
char = gets.chomp

puts "Count of char in the string: #{count_char(string, char)}"

0 comments on commit 924ce0a

Please sign in to comment.