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 strings, you are allowed to check the given characters present in the string using the given functions. These functions are defined under strings package, so you have to import strings package in your program to access these functions:
1. Contains: This function is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false.
func Contains(str, chstr string) bool
Here, str is the original string and chstr is the string which you wants to check. Let us discuss this concept with the help of an example:
Original strings String 1: Welcome to Geeks for Geeks String 2: Here! we learn about go strings Result 1: true Result 2: false
2. ContainsAny: This function is used to check whether any Unicode code points in chars are present in the given string. If any Unicode code points in chars are available in the given string, then this method returns true, otherwise, return false.
func ContainsAny(str, charstr string) bool
Here, str is the original string and charstr is the Unicode code points in chars. Let us discuss this concept with the help of an example:
Result 1: true Result 2: false Result 3: true Result 4: true Result 5: true Result 6: false
- How to count specific characters present in the slice in Golang?
- Check if the specified element is present in the slice of bytes in Golang
- Golang | Finding Index of the Regular Expression present in String
- How to Replace Characters in Golang String?
- How to Count the Number of Repeated Characters in a Golang String?
- How to check the specified rune in Golang String?
- Check if the String ends with specified suffix in Golang
- Check if the String starts with specified prefix in Golang
- How to check String for equality under Unicode case folding in Golang?
- Golang | Finding Index of the Regular Expression present in Slice
- Check if the given slice is sorted in Golang
- Check If the Rune is a Letter or not in Golang
- How to Trim a String in Golang?
- How to Split a String in Golang?
- Check If the Rune is a Lowercase Letter or not in Golang
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.