What is the strconv.CanBackquote() function in Golang?

Overview

The CanBackquote() method of strconv package is used to determine whether or not a given string can be expressed unchanged as a single-line backquoted string without control characters other than a tab.

Syntax

func CanBackquote(s string) bool

Parameter

  • s: This is the string value to be checked.

Return type

A Boolean type value is returned.

Return value

The CanBackquote() function returns true if the string can be represented unchanged as a single-line backquoted. Otherwise, it returns false.

Code

The following code shows how to implement the CanBackquote() function in Golang:

Note: To use the CanBackquote() function, we must import the strconv package in our program.

// Golang program
// Using strconv.CanBackquote() Function
package main
import (
"fmt"
"strconv"
)
func main() {
// declare a variable of string type
var str string
// assign value
str = `"Keep Coding ☺"`
// CanBackquote() function returns true
// if the string can be represented unchanged
// as a single-line backquoted.
fmt.Println(strconv.CanBackquote(str))
// reassign value
str = "`Hello, Ally`"
// CanBackquote() function returns true
// if the string can be represented unchanged
// as a single-line backquoted.
fmt.Println(strconv.CanBackquote(str))
// reassign value
str = `"Golang is statically typed "`
// CanBackquote() function returns true
// if the string can be represented unchanged
// as a single-line backquoted.
fmt.Println(strconv.CanBackquote(str))
}