In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
In Go string, you can count some specific Unicode code points or the number of non-overlapping instances of costr (Repeated Characters) in the string with the help of Count() function. This function returns a value which represents the total number of the given string or Unicode code points present in the string. It is defined under the strings package so, you have to import strings package in your program for accessing Count function.
func Count(str, costr string) int
Here, str is the original string and costr is a string which we want to count. If the value of costr is empty, then this function returns 1 + the number of Unicode code points in str.
String 1: Welcome to the online portal of GeeksforGeeks String 2: My dog name is Dollar String 3: I like to play Ludo Result 1: 6 Result 2: 1 Result 3: 20 Result 4: 0
- How to count specific characters present in the slice in Golang?
- How to Replace Characters in Golang String?
- Check if the given characters is present in Golang String
- Repeating a String for Specific Number of Times in Golang
- How to Trim a String in Golang?
- How to Split a String in Golang?
- Golang | Splitting the string after the specified separator
- How to check the specified rune in Golang String?
- How to find the last index value of specified string in Golang?
- How to find the index value of specified string in Golang?
- How to convert a string in uppercase in Golang?
- Golang | How to find the index of rune in the string?
- Check if the String starts with specified prefix in Golang
- Check if the String ends with specified suffix in Golang
- Golang | Checking the string for the specified regular expression
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.