File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 9797# @author https://github.com/SuperFola
9898(let setAt (fun (_str _index _x) (builtin__string:setAt _str _index _x)))
9999
100+ # @brief Count the number of non-overlapping occurrences of a word in a string
101+ # @param _str string to search into
102+ # @param _word word to count occurrences of
103+ # =begin
104+ # (string:count "the three truths" "th") # 3
105+ # =end
106+ # @author https://github.com/SuperFola
107+ (let count (fun (_str _word) {
108+ (mut _count 0)
109+ (mut _next (find _str _word))
110+ (while (!= -1 _next) {
111+ (set _count (+ 1 _count))
112+ (set _next (findAfter _str _word (+ _next (len _word)))) })
113+ _count }))
114+
100115# @brief Converts the given character to lowercase.
101116# @param _string the string to make lowercase
102117# @details The original string is left unmodified.
Original file line number Diff line number Diff line change 1212 (test:eq (builtin__string:ord "a") (string:ord "a"))
1313 (test:eq (builtin__string:chr 65) (string:chr 65))
1414
15+ (test:eq 3 (string:count "the three truths" "th"))
16+ (test:eq 0 (string:count "the three truths" "thz"))
17+ (test:eq 2 (string:count "ababababab" "abab"))
18+
1519 (test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
1620 (test:eq "abcdefghijklmnopqrstuvwxyz" (string:toLower "abcdefghijklmnopqrstuvwxyz"))
1721 (test:eq "ABCDEFGHIJKLMNOPQRSTUVWXYZ" (string:toUpper "abcdefghijklmnopqrstuvwxyz"))
You can’t perform that action at this time.
0 commit comments