Last active
March 5, 2023 21:35
-
-
Save stevedoyle/e222ee905e62148aa7f752fa333068d1 to your computer and use it in GitHub Desktop.
Go: Reading a string with spaces from stdin using bufio
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 ( | |
"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