Count occurrences of a substring: Difference between revisions

m
→‎{{header|Ruby}}: Stop using Array#count, because it needs Ruby 1.8.7.
No edit summary
m (→‎{{header|Ruby}}: Stop using Array#count, because it needs Ruby 1.8.7.)
Line 422:
 
=={{header|Ruby}}==
<lang ruby>irb(main):001:0> "the three truths".scan("th").countlength
=> 3
irb(main):002:0> "ababababab".scan("abab").countlength
=> 2</lang>
 
String#scan returns an array of substrings, and Array#countlength (or Array#length or Array#size) counts them.
 
=={{header|SNOBOL4}}==
Anonymous user