Saved Bookmarks
| 1. |
Write a Golang code for checking if the given characters are present in a string. |
|
Answer» We can do this by using the CONTAINS() method from the STRINGS package. package main IMPORT ( "fmt" "strings") // Main functionfunc main() { // Create and initialize string1 := "WELCOME to Interviewbit" string2 := "Golang Interview Questions" // Check for presence Using Contains() method of strings package res1 := strings.Contains(string1, "Interview") res2 := strings.Contains(string2, "Go") // Displaying the result fmt.Println("Is 'Interview' PRESENT in string1 : ", res1) fmt.Println("Is 'Go' present in string2: ", res2) }The output of this code is: Is 'Interview' present in string1 : trueIs 'Go' present in string2: true |
|