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