Posted at

[Ruby] 特定の文字列カウント

More than 1 year has passed since last update.


一文字

"hoge hoge".count('h')  # => 2


文字列

"hoge hoge".scan('hoge').size  # => 2