Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
Last active March 5, 2023 21:35
Show Gist options
  • Save stevedoyle/e222ee905e62148aa7f752fa333068d1 to your computer and use it in GitHub Desktop.
Save stevedoyle/e222ee905e62148aa7f752fa333068d1 to your computer and use it in GitHub Desktop.
Go: Reading a string with spaces from stdin using bufio
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
fmt.Print("Enter a string: ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
input := scanner.Text()
input = strings.ToLower(input)
if strings.HasPrefix(input, "i") &&
strings.HasSuffix(input, "n") &&
strings.Contains(input, "a") {
fmt.Println("Found!")
} else {
fmt.Println("Not Found!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment