Skip to content

Instantly share code, notes, and snippets.

@akolybelnikov
Created November 1, 2018 20:33
Show Gist options
  • Save akolybelnikov/24095c7ceefddc5e1da22c4196a013ae to your computer and use it in GitHub Desktop.
Save akolybelnikov/24095c7ceefddc5e1da22c4196a013ae to your computer and use it in GitHub Desktop.
Find characters in a string challenge in Go
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