I use this, to collect a input and display the input then, but when I do it like this the “something” text will be displayed in a new line, but I want the text to be displayed in the same line, any ideas?
func main() {
fmt.Println("Example")
print("example: ")
in := bufio.NewReader(os.Stdin);
input, err := in.ReadString('\n');
if err != nil {
fmt.Println("Error: ", err)
}
fmt.Println(input, "something")
}
fmt.Println()automatically appends a newline to the end of it’s output.You could try using Printf, which takes a “format string” and a list of inputs.
An example would be:
In this case, %s is a placeholder for a string type.
All the placeholders can be found in the fmt godoc: http://golang.org/pkg/fmt/
Also if the input itself has a newline at the end, you can use
Trimfrom the packagestringsto pull off the \n character.