Last active
May 3, 2018 19:58
-
-
Save jcamilom/7a424a0940109a6e6943c3ac83111c14 to your computer and use it in GitHub Desktop.
[Remove new line from input] Remove the new line char from a string acquired using io.Reader.ReadString. Solution from https://flaviocopes.com/golang-remove-new-line-from-readstring/ #golang #go #input
This file contains hidden or 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" | |
"os" | |
"strings" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
text, _ := reader.ReadString('\n') | |
text = strings.TrimSuffix(text, "\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment