×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to iterate characters using the each_char() function

Last Updated : December 15, 2025

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!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.