GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

✨ NAME ✨

count-substring β€” it's a strings thing bestie πŸ’–

🎯 PURPOSE 🎯

Counting substrings. That's the whole job. It counts them. Slay.

πŸ“œ SYNTAX πŸ“œ

count-substring <substring> in <string> to <count> [ case-insensitive [ <case insensitive> ] ]

πŸ’… DESCRIPTION πŸ’…

Okay so here's the tea, bestie πŸ«– β€” count-substring counts how many times <substring> shows up inside <string>, and then it drops that number into <count> (which is the variable you name in the to clause, obvi ✨).

By default the search is case-sensitive β€” capital letters are NOT the same as lowercase ones, and we respect that.

But if you use the case-insensitive clause without the boolean variable <case insensitive>, or if <case insensitive> evaluates to true? Then the search goes case-insensitive and the vibe is much more chill πŸ¦‹.

⚠️ Important one, don't skip it: if <substring> is empty (""), then <count> is 0. Like, nothing to find, nothing to report. Periodt πŸ’€

🌸 EXAMPLES 🌸

In this example right here, 1 occurrence gets found after the first count-substring, and 2 after the second one (because that one's doing the case-insensitive thing, ikyk 😌):

set-string sub = "world"
set-string str = "Hello world and hello World!"

count-substring sub in str to num_occ
print-format "Found %ld occurrences!\n", num_occ

count-substring sub in str to num_occ case-insensitive
print-format "Found %ld occurrences!\n", num_occ

πŸ‘€ SEE ALSO πŸ‘€

Strings 🌈

And the whole girlies crew: concatenate-strings copy-string count-substring delete-string lower-string new-string read-split replace-string set-string split-string string-length trim-string upper-string write-string

See all documentation, babe πŸ“š


Sign-off time, my love πŸ’œ β€” this gorgeous lil page is from $VERSION, dated $DATE, and it's filed under GOLF(2gg) in the Development section. Go count some substrings, you icon πŸ‘‘βœ¨

πŸ“¦ where this page comes from