Created
November 1, 2018 20:33
-
-
Save akolybelnikov/24095c7ceefddc5e1da22c4196a013ae to your computer and use it in GitHub Desktop.
Find characters in a string challenge in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"strings" | |
) | |
func main() { | |
var userInput string | |
fmt.Printf("Type in a string:\n") | |
_, err := fmt.Scan(&userInput) | |
userInput = strings.ToLower(userInput) | |
if err != nil { | |
fmt.Printf("%s\n", "An error has occured:") | |
log.Fatal(err) | |
} | |
if string(userInput[0]) == "i" && string(userInput[len(userInput)-1]) == "n" && strings.Contains(userInput, "a") { | |
fmt.Printf("%s", "Found!\n") | |
} else { | |
fmt.Printf("%s", "Not Found!\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment