Ruby | String casecmp? Method
casecmp? is a String class method in Ruby which is used to return true if both the string are equal after Unicode case folding and false if they are not equal.
Syntax: str.casecmp?(other_str)
Parameters: Here, str is the given string to be checked and other_str is the string to which str is compared.
Returns: This method will returns the numbers based on the equality of the str and other_str. It can also return nil if the two strings have incompatible encodings, or if other_str is not a string.
Example 1:
# Ruby program to demonstrate # the casecmp? method # Taking a string and # using the method puts "RuBy".casecmp?("ruby") puts "GeeksforGeeks".casecmp?("gfg") |
Output:
true false
Example 2:
# Ruby program to demonstrate # the casecmp? method # Taking a string and # using the method # here it will give nil puts "\u{e5 f6 dc}".encode("ISO-8859-1").casecmp?("\u{c4 d4 de}") puts "GFG".casecmp?("250") |
Output:
false
Recommended Posts:
- Ruby | String casecmp Method
- Ruby | Symbol casecmp function
- Ruby | String eql? Method
- Ruby | String =~ Method
- Ruby | String === Method
- Ruby | String chr Method
- Ruby | String <=> Method
- Ruby | String == method
- Ruby | String << Method
- Ruby | String * Method
- Ruby | String + Method
- Ruby | String hex Method
- Ruby | String each_byte Method
- Ruby | String delete_prefix! Method
- Ruby | String center() 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.


