user2713086
user2713086

Reputation: 49

golang adding spaces after strings by default?

I'm learning Go and one annoyance I have with it is when i use fmt.Println it adds a space after every argument passed (even variables). Is there a way to remove this space so it only adds a space if I add one in quotes?

Upvotes: 1

Views: 7044

Answers (3)

David Budworth
David Budworth

Reputation: 11626

If you want something that works like println, where you don't have to put %v markers, then fmt.Print does the job.

it doesn't add spaces between arguments, and also doesn't add a newline.

for example:

fmt.Print("a","b","c","\n")

prints: abc

Upvotes: 2

Grzegorz Żur
Grzegorz Żur

Reputation: 49181

Use "Printf" function with format string instead.

fmt.Printf("string %s, integer %d, anything %v\n", "hello", 1, struct {}{})

Upvotes: 3

Kipz
Kipz

Reputation: 193

Try it like this

func main() {
    fmt.Println("With","Space")
    fmt.Printf("%s%s\n","No","Space")
}

example

Upvotes: 2

Related Questions