Count occurrences of a substring: Difference between revisions
Content deleted Content added
→{{header|SNOBOL4}}: Add Ruby. |
|||
Line 402:
>>> "ababababab".count("abab")
2</lang>
=={{header|Ruby}}==
<lang ruby>irb(main):001:0> "the three truths".scan("th").count
=> 3
irb(main):002:0> "ababababab".scan("abab").count
=> 2</lang>
String#scan returns an array of substrings, and Array#count (or Array#length or Array#size) counts them.
=={{header|SNOBOL4}}==
|