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() |
chevron_right
filter_none
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() |
chevron_right
filter_none
Output:
G F G G 4 G
Recommended Posts:
- Ruby | String <=> Method
- Ruby | String + Method
- Ruby | String eql? Method
- Ruby | String * Method
- Ruby | String === Method
- Ruby | String =~ Method
- Ruby | String << Method
- Ruby | String chr Method
- Ruby | String == method
- Ruby | String hex Method
- Ruby | String chop Method
- Ruby | String index Method
- Ruby | String delete() Method
- Ruby | String delete! Method
- Ruby | String chomp Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


