package main
import (
"fmt"
"os"
"strings"
)
func main() {
arguments := os.Args
words := strings.Split(arguments[1], "\n")
fmt.Println(words)
fmt.Println(words[0])
}
example:
go run main.go "hello\nthere"
output:
[hello\nthere]
hello\nthere
expected:
[hello there]
hello
why does the separator for the newline "\n"
needs to be escaped "\\n"
to get the expected result?
Because you don't need to escape the newline if used like this https://play.golang.org/p/UlRISkVa8_t