Ruby | String chars() Method
chars is a String class method in Ruby which is used to return an array of characters in str.
Syntax: str.chars
Parameters: Here, str is the given string
Returns: An array of the characters.
Example 1:
# Ruby program to demonstrate # the chars method # Taking a string and # using the method puts "Ruby String" .chars() puts "Methods" .chars() |
Output:
R u b y S t r i n g M e t h o d s
Example 2:
# Ruby program to demonstrate # the chars method # Taking a string and # using the method puts "GFG" .chars() puts "G4G" .chars() |
Output:
G F G G 4 G
Contact Us