Golang strconv.CanBackquote() function example

package strconv

Golang strconv.CanBackquote() function usage example

 package main

 import (
  "fmt"
  "strconv"
 )

 func quote(s string) string {
  if strconv.CanBackquote(s) {
 return "`" + s + "`"
  }
  return strconv.Quote(s)
 }

 func main() {

  fmt.Println(quote("abc123")) // can back quote
  
  fmt.Println(quote("a`b")) // cannot back quote
 }

Reference :

http://golang.org/pkg/strconv/#CanBackquote

Advertisement