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.
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.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to iterate characters using each_char() function is given below. The given program is compiled and executed successfully.
Output:
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