Skip to content

Instantly share code, notes, and snippets.

@jcamilom
Last active May 3, 2018 19:58
Show Gist options
  • Save jcamilom/7a424a0940109a6e6943c3ac83111c14 to your computer and use it in GitHub Desktop.
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
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