Quantcast
Channel: Finding exact number of a given symbol at the beginning of a string - Stack Overflow
Browsing latest articles
Browse All 3 View Live

Answer by Gazler for Finding exact number of a given symbol at the beginning...

Depends on what your string manipulations are.You can determine the number of consecutive a's by doing:string.match(/^(a{1,3}).*/)[1].sizeYou haven't defined the rules, so mine are:"a" - downcase"aa" -...

View Article


Answer by Dominik Honnef for Finding exact number of a given symbol at the...

Why not use a modified version of the first regexp and then simply count the a's it returns? A lam = string.match(/^(a{1,3})/)case m[1].size when 1 when 2 when 3endOf course you can also use an array...

View Article


Finding exact number of a given symbol at the beginning of a string

I'm trying to solve a Ruby problem using as less code as possible :). I want to check if a given string starts with a varying number of symbols, lets say between one and three 'a'. That's easy using...

View Article
Browsing latest articles
Browse All 3 View Live


Latest Images