Given a string, the task is to count the number of words being repeated in that particular string in Golang.
Input: s = "She is mother of my mother." Output: She = 1 is = 1 mother = 2 of = 1 my = 1
To count the number of repeating words, first, the string is taken as input and then strings.Fields() function is used to split the string. A function “repetition” is defined to count the number of words getting repeated.
Below is the program in Golang to count the number of repeating words in a given string.
the = 3 , = 2 bitter = 2 to = 1 make = 1 better = 1 betty = 2 bought = 2 butter = 4 was = 1 more = 1
Explanation: In the above program, we first take a string as an input and then split that string using strings.Fields() function. If the same word has occurred, the count increases by one else value 1 is returned that implies that word occurs only once in the string.
- Repeating a String for Specific Number of Times in Golang
- Program to find the Length of the longest substring without repeating characters in Golang
- How to replace all words with another words in HTML ?
- Counting inversions in an array using segment tree
- GRE Data Analysis | Counting Methods
- How to Count the Number of Repeated Characters in a Golang String?
- string.Contains Function in Golang with Examples
- Converting a string variable into Boolean, Integer or Float type in Golang
- Golang Program that uses String Switch
- How to Trim a String in Golang?
- How to convert a string in uppercase in Golang?
- How to convert a string in lower case in Golang?
- Check if the given characters is present in Golang String
- How to Split a String in Golang?
- How to find the index value of specified string in Golang?
- How to find the last index value of specified string in Golang?
- Check if the String starts with specified prefix in Golang
- Check if the String ends with specified suffix in Golang
- How to check String for equality under Unicode case folding in Golang?
- Golang | How to find the index of rune in the string?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.