SyntaxFix
Write A Post
Hire A Developer
Questions
Tags
For example, str = 'abcdefg'. How do I find the index if c in this string using Ruby?
str = 'abcdefg'
c
This question is related to ruby string indexing
ruby
string
indexing
str="abcdef" str.index('c') #=> 2 #String matching approach str=~/c/ #=> 2 #Regexp approach $~ #=> #<MatchData "c">
Hope it helps. :)
You can use this
"abcdefg".index('c') #=> 2
Source: Stackoverflow.com