Techieindoor

Go – How to print backslash in strings in go

Here, We will see how to print backslash in strings in go. It is very easy to print something to the standard output in Go. You have to just import fmt package and call Print(), Println() or Printf() function.

To print backslash in string, You just need to prepend one more backslash before to be printed backslash.

Go interpreter treats single backslash as escape sequence character. When you put two backslash then Go interpreter treats it as a single backslash character.

Example with code:

package main

import (
  "fmt"
)

func main() {

  fmt.Println("Hello \\ go")

  fmt.Println("Hello \\\\ go")

  fmt.Println("Hello \\\\\\ go")

}

Output:

Hello \ go
Hello \ go
Hello \\ go

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Exit mobile version