Want "30 of month" but get "30"
package main
import "fmt"
func main() {
var s string
fmt.Scanln(&s)
fmt.Println(s)
return
}
$ go run test.go
31 of month
31
Scanln is similar to Scan, but stops scanning at a newline and after the final item there must be a newline or EOF.
The fmt Scan family scan space-separated tokens.
You can try bufio scan
If you really want to include the spaces, you may consider using
fmt.Scanf()
with format%q a double-quoted string safely escaped with Go syntax
, for example:Run it and:
Here is the working program
which reads strings like " d skd a efju N" and prints the same string as output.