Ruby | String include? Method
include? is a String class method in Ruby which is used to return true if the given string contains the given string or character.
Syntax: str.include?
Parameters: Here, str is the given string.
Returns: true if the given string contains the given string or character otherwise false.
Example 1:
# Ruby program to demonstrate # the include? method # Taking a string and # using the method puts "Ruby".include? "by" puts "String".include? "ui" |
chevron_right
filter_none
Output:
true false
Example 2:
# Ruby program to demonstrate # the include? method # Taking a string and # using the method puts "Sample".include? "am" puts "Input".include? "pt" |
chevron_right
filter_none
Output:
true false
Recommended Posts:
- Include v/s Extend in Ruby
- Ruby | Set include?() function
- Ruby | Hash include?() function
- Ruby | Range include?() function
- Ruby | Enumerable include?() function
- Ruby | Array class include?() operation
- Ruby | String =~ Method
- Ruby | String * Method
- Ruby | String chr Method
- Ruby | String hex Method
- Ruby | String + Method
- Ruby | String <=> Method
- Ruby | String eql? Method
- Ruby | String << Method
- Ruby | String === 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.


