×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang strconv.CanBackquote() Function with Examples

Golang | strconv.CanBackquote() Function: Here, we are going to learn about the CanBackquote() function of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 07, 2021

strconv.CanBackquote()

The CanBackquote() function is an inbuilt function of the strconv package which is used to check whether the given string can be represented unchanged as a single-line backquoted string without control characters other than tab.

It accepts one parameter (s string) and returns true if the string can be represented unchanged as a single-line backquoted; false, otherwise.

Syntax

func CanBackquote(s string) bool

Parameters

  • s : A string value to be checked.

Return Value

The return type of the CanBackquote() function is bool, it returns true if the string can be represented unchanged as a single-line backquoted; false, otherwise.

Example 1

// Golang program to demonstrate the
// example of strconv.CanBackquote() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	fmt.Println(strconv.CanBackquote("Hello,there"))
	fmt.Println(strconv.CanBackquote("Hi Buddy ☺"))
	fmt.Println(strconv.CanBackquote(`"Hello,there"`))
	fmt.Println(strconv.CanBackquote(`"Hi Buddy ☺"`))

	fmt.Println("------")
	fmt.Println(strconv.CanBackquote("`Hello,there`"))
	fmt.Println(strconv.CanBackquote("`Hi Buddy ☺`"))
}

Output:

true
true
true
true
------
false
false

Example 2

// Golang program to demonstrate the
// example of strconv.CanBackquote() Function

package main

import (
	"fmt"
	"strconv"
)

func main() {
	// Checking with tabs
	fmt.Println(strconv.CanBackquote("Hello,there"))
	fmt.Println(strconv.CanBackquote("Hello,there\n"))
	fmt.Println(strconv.CanBackquote("Hello,there\r"))
	fmt.Println(strconv.CanBackquote("Hello,there\a"))
	fmt.Println(strconv.CanBackquote("Hello,there\t"))
}

Output:

true
false
false
false
true

Golang strconv Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.