How to use strconv.CanBackquote() Function in Golang?

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate
// strconv.CanBackquote() Function
package main
  
import (
    "fmt"
    "strconv"
)
  
func main() {
    // Checking whether the given
    // string can be represented
    // unchanged as a single-line 
    // backquoted string
    // Using CanBackquote() function
    fmt.Println(strconv.CanBackquote("Welcome to GeeksforGeeks"))
    fmt.Println(strconv.CanBackquote("`Welcome to GeeksforGeeks`"))
    fmt.Println(strconv.CanBackquote(`"Welcome to GeeksforGeeks"`))
  
}

chevron_right


Output:

true
false
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate
// strconv.CanBackquote() Function
package main
  
import (
    "fmt"
    "strconv"
)
  
// Main function
func main() {
  
    // Checking whether the given
    // string can be represented
    // unchanged as a single-line
    // backquoted string
    // Using CanBackquote() function
    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.")
    }
  
}

chevron_right


Output:

The given string is unchanged single-line backquoted string.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.