ADVERTISEMENT
ADVERTISEMENT

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 »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.