Golang in sixty seconds — Count occurrences in a string

Richard Bell
Dev Genius
Published in
1 min readDec 3, 2021

--

Photo by luis arias on Unsplash

Did you ever want to quickly count how many times the letter s appears in Mississippi? Well Go has your back:

strings.Count("Mississippi", "s") // 4

One of the most common code golf challenges I’ve seen is to count the occurrences of a letter in a string and do something with the information. Let’s change every letter the word “Mississippi”…

--

--

Father to two beautiful baby girls | Husband to a generous wife | Lead Software Engineer | Hobby collector | Support me at ko-fi.com/richardtbell