Skip to content

Instantly share code, notes, and snippets.

@aarti
Created December 19, 2013 20:45
Show Gist options
  • Save aarti/8045984 to your computer and use it in GitHub Desktop.
Save aarti/8045984 to your computer and use it in GitHub Desktop.
Different ways to to find a string in another string
string = "HOPJYJKCONNECTICUTQZIDAHOKR"
states = ["TEXAS", "ALASKA", "IDAHO", "FLORIDA", "MONTANA", "OHIO", "NEWMEXICO", "CONNECTICUT", "COLORADO"]
states.select { |s| string[s] }
states.select { |s| string.match s }
states.select { |s| string.include? s }
# => ["IDAHO", "CONNECTICUT"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment