Count occurrences of a substring: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL 68}}: typo) |
mNo edit summary |
||
Line 1,561: | Line 1,561: | ||
(let ((substrings)) ; empty list to add occurrences of SUBSTRING as we find them |
(let ((substrings)) ; empty list to add occurrences of SUBSTRING as we find them |
||
(while (string-match substring text) ; as long as we can find SUBSTRING in TEXT |
(while (string-match substring text) ; as long as we can find SUBSTRING in TEXT |
||
(push (match-string 0 text) substrings) |
(push (match-string 0 text) substrings) ; add the SUBSTRING we found to the list of substrings |
||
(setq text (replace-match "" nil nil text))) ; remove SUBSTRING from text, and repeat while loop |
(setq text (replace-match "" nil nil text))) ; remove SUBSTRING from text, and repeat while loop |
||
(length substrings))) ; count number of items in substrings list |
(length substrings))) ; count number of items in substrings list |