Home > Article > Backend Development > How to Capture \'30 of month\' Input with fmt.Scanln?
Resolving "30 of month" Input Retrieval with fmt.Scanln
In the original code, utilizing fmt.Scanln posed a challenge when attempting to retrieve "30 of month" as input. The function reads space-separated tokens, resulting in the retrieval of "30" without the intended "of month."
Solutions:
<code class="go">var s1 string var s2 string fmt.Scanln(&s1, &s2) fmt.Println(s1) // Prints "30" fmt.Println(s2) // Prints "of month"</code>
<code class="go">scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { s := scanner.Text() fmt.Println(s) // Prints "30 of month" } if err := scanner.Err(); err != nil { os.Exit(1) }</code>
The above is the detailed content of How to Capture \'30 of month\' Input with fmt.Scanln?. For more information, please follow other related articles on the PHP Chinese website!