Trouble Counting Subseq of a String Common Lisp -
i trying use function count tell me how many occurrences of "<script>" tag there can't seem working. code:
(count "<script>" "<p>hello world</p><script>javascript goes here</script>" :key #'string :test #'equal)
i can't seem find examples of did find 1 remove , figured similar. how can return 1 not 0?
count
counts single elements match (so use count #\a characters example, not substrings). counting substrings you'll want this:
(defun count-substrings (substring string) (loop sub-length = (length substring) 0 (- (length string) sub-length) when (string= string substring :start1 :end1 (+ sub-length)) count it))
of course counting html tags pretty error prone. you'll want use actual parser.
Comments
Post a Comment