Q:

Ruby program to iterate characters using the each_char() function

belongs to collection: Ruby Strings Programs

0

In this program, we will create a string and iterate the characters of the string using the each_char() function and print the character of the string.

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 iterate characters using each_char() function is given below. The given program is compiled and executed successfully.

# Ruby program to iterate characters of a 
# string using each_char() function

str = "Hello how are you";

str.each_char { |ch| print ch," " };

Output:

H e l l o   h o w   a r e   y o u

Explanation:

In the above program, we created three strings str initialized with "Hello how are you". Then we iterated the string characters and printed them.

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 convert the string into an array o... >>
<< Ruby program to concatenate the strings using the ...