+ 6

Index of arrays

How can I get the index of an array/string value? For Example: x = "Hello Bro" puts x.where_yo_at_doe['H'] #where_yo_at_doe is not a legit method but how can I make it output: 0 ? (Because H is 0 and e is 1) Does this make sense?

29th Mar 2017, 1:59 PM
MrCoder
MrCoder - avatar
3 Respostas
+ 17
puts x.index('H') // returns 0 Source: http://stackoverflow.com/a/10668473
29th Mar 2017, 2:55 PM
Jafca
Jafca - avatar
+ 6
@Sean Kudebeh I'm trying to get the index of H :D @Jafca Thanks man :D
29th Mar 2017, 11:23 PM
MrCoder
MrCoder - avatar
+ 2
Are you trying to get the character "e" from the string "Hello Bro" ?
29th Mar 2017, 2:10 PM
Sean Kudebeh
Sean Kudebeh - avatar