×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Which format verb with fmt.Printf() is used to print the double-quoted string in Go?

Learn how to print the double-quoted text/string using the fmt.Printf() in Golang?
Submitted by IncludeHelp, on October 04, 2021

In Go programming language, fmt.Printf() function is an inbuilt function of fmt package, it is used to format according to a format specifier and writes to standard output.

To print the double-quoted string/text using the fmt.Printf() function – we use %q format verb.

Example 1:

package main

import (
	"fmt"
)

func main() {
	x := "IncludeHelp.Com"
	fmt.Printf("%s\n", x)
	fmt.Printf("%q\n", x)
}

Output:

IncludeHelp.Com
"IncludeHelp.Com"

Example 2:

// Golang program to demonstrate the
// example of %q format verb

package main

import "fmt"

func main() {
	// Declaring some variable with the values
	x := "Hello"
	y := "Hello, World!"

	// Printing double-quoted text
	fmt.Printf("%q\n", x)
	fmt.Printf("%q\n", y)
}

Output:

"Hello"
"Hello, World!"

Golang FAQ »



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.