Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare a string against multiple other strings

Tags:

ruby

Is there a method that let me compare one String with multiple others in Ruby? I really would like to do something like this:

myString.eql?(["string1","string2","string3"]) 
like image 989
auralbee Avatar asked Sep 22 '10 14:09

auralbee


People also ask

How do I compare strings with different strings?

Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.

Can I use == to compare two strings?

You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.


1 Answers

["string1","string2","string3"].include? myString 
like image 109
mipadi Avatar answered Sep 24 '22 12:09

mipadi