The strconv package’s Unquote()
function is used to read the given string s
as a single-quoted, double-quoted, or backquoted string and return the string value that s
quotes.
func Unquote(s string) (string, error)
s
: This is the value of the quoted string from which the string is obtained.The Unquote()
function returns the string value quoted by the specified string s
.
Note: The
Unquote()
function returns the equivalent one-character string if there is a single-quoted string.
The following code shows how to implement the strconv.Unquote()
function in Golang.
// using strconv.Unquote() Function in Golangpackage mainimport ("fmt""strconv")func main() {// declare variable s, err and assign value to its, err := strconv.Unquote("`Golang is one of my favourite programming languages`")// display resultfmt.Printf("The value for s: %q, and error: %v\n", s, err)// reassigning value to s, errs, err = strconv.Unquote("Golang is one of my favourite programming languages")// display resultfmt.Printf("The value for s: %q, and error: %v\n", s, err)}
main
package.main()
function.s
and err
, pass a value to the Unquote()
function, and assign it to the variables.Note: If the value of
s
is syntactically valid, then the error will be<nil>
.