Go String
A succession of characters is known as a string. “Golang,” for example, is a string made up of the letters G, o, l, a, n, and g.
In Go, double quotes are used to denote strings. For instance,
// using var
var name1 = "Go Programming"
// using shorthand notation
name2 := "Go Programming"
Name1 and name2 are both strings with the value “Go Programming” in them.
Example: Golang String
// Program to create a string in Golang
package main
import "fmt"
func main() {
// creating string using var
var message1 = "Hello,"
// creating string using shorthand notation message2 := "Welcome to Learn Code Zone"
fmt.Println(message1)
fmt.Println(message2)
}
Output
Hello,
Welcome to Learn Code Zone
Golang String using backtick
In Go, we can also represent strings using the backtick notation, ` `. For example,
// To represent a string with a backtick
package main
import "fmt"
func main() {
// representing string with ` `
message := `I love Go Programming`
fmt.Println(message)
}
Output
I love Go Programming