Quantcast
Channel: Finding # occurrences of a character in a string in Ruby - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Melanie Palen for Finding # occurrences of a character in a string...

I was able to solve this by passing a string through scan as shown in another answer.For example:string = 'This is an example'puts string.count('e')Outputs:2I was also able to pull the occurrences by...

View Article



Answer by steenslag for Finding # occurrences of a character in a string in Ruby

If you just want the number of a's: puts "Melanie is a noob".count('a') #=> 2Docs for more details.

View Article

Answer by Shiv for Finding # occurrences of a character in a string in Ruby

This link from a question asked previously should helpscanning a string in Rubyscan returns all the occurrences of a string in a string as an array, so"Melanie is a noob".scan(/a/)will return ["a","a"]

View Article

Finding # occurrences of a character in a string in Ruby

I'm looking for the Ruby method (1.9...) that can help me find the number of occurrences of a character in a string. I'm looking for all occurrences, not just the first one.For example: "Melanie is a...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images