ADVERTISEMENT
ADVERTISEMENT

Ruby program to iterate characters using the each_char() function

Ruby Example: Write a program to iterate characters using the each_char() function.
Submitted by Nidhi, on January 06, 2022

Problem Solution:

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.

Ruby Strings Programs »


ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.