How to use strconv.CanBackquote() Function in Golang?
Last Updated :
03 May, 2020
Go language provides inbuilt support to implement conversions to and from string representations of basic data types by strconv Package. This package provides a CanBackquote() function which is used to check whether the string str can be represented unchanged as a single-line backquoted string without control characters other than a tab or not. To access CanBackquote() function you need to import strconv Package in your program with the help of import keyword.
Syntax:
func CanBackquote(str string) bool
Parameter: This function takes one parameter of string type, i.e., str.
Return value: This function returns true if the string str can be represented unchanged as a single-line backquoted string, otherwise return false.
Let us discuss this concept with the help of the given examples:
Example 1:
package main
import (
"fmt"
"strconv"
)
func main() {
fmt.Println(strconv.CanBackquote( "Welcome to GeeksforGeeks" ))
fmt.Println(strconv.CanBackquote( "`Welcome to GeeksforGeeks`" ))
fmt.Println(strconv.CanBackquote(` "Welcome to GeeksforGeeks" `))
}
|
Output:
true
false
true
Example 2:
package main
import (
"fmt"
"strconv"
)
func main() {
res := strconv.CanBackquote( "Welcome to GeeksforGeeks" )
if res == true {
fmt.Println( "The given string is unchanged " +
"single-line backquoted string." )
} else {
fmt.Println( "The given string is a " +
"changeable single-line backquoted string." )
}
}
|
Output:
The given string is unchanged single-line backquoted string.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...