Today I wanted to get a number from stdin, and before being able to convert it to integer using strconv.Atoi I had to remove the new line char. How?


Using strings.TrimSuffix:

package main

import (

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, "\n")

Want to hire me?

I'm currently considering remote job/contract opportunities as a Frontend Developer.

Read more about me and if you're interested, get in touch.