Q:

Ruby program to count a specified character inside the string

belongs to collection: Ruby Strings Programs

0

In this program, we will create a string and then count the specified character inside the string using the count() method.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to count a specified character inside the string is given below. The given program is compiled and executed successfully.

# Ruby program to count a specified character 
# inside the string

str = "aaabbcccddddd";

result = str.count('c');

print "Count: ", result;

Output:

Count: 3

Explanation:

In the above program, we created a string str initialized with "aaabbcccddddd". Then we count the specified character 'c' using the count() function and print the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Strings Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< Ruby program to remove the last specified characte...