GOLF(2gg)
β¨ 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>is0. 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
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms