×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang strconv.AppendQuoteToASCII() Function with Examples

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

strconv.AppendQuoteToASCII()

The AppendQuoteToASCII() function is an inbuilt function of the strconv package which is used to append the double-quoted Go string literal representing s (as generated by QuoteToASCII() function), to dst and returns the extended buffer. Where dst is the first parameter of []byte type and s is the second parameter of string type.

It accepts two parameters (dst, s) and returns the extended buffer.

Syntax

func AppendQuoteToASCII(dst []byte, s string) []byte

Parameters

  • dst : A byte array (or byte slices) in which we have to append the double-quoted Go string literal.
  • s : String to be appended.

Return Value

The return type of AppendQuoteToASCII() function is a []byte, it returns the extended buffer after appending the double-quoted string.

Example 1

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	x := []byte("QuoteToASCII:")
	fmt.Println("Before AppendQuoteToASCII()")
	fmt.Println(string(x))

	// Appending a quote to the x
	x = strconv.AppendQuoteToASCII(x, `"If you can dream it, you can do it."`)
	fmt.Println("After AppendQuoteToASCII()")
	fmt.Println(string(x))
}

Output:

Before AppendQuoteToASCII()
QuoteToASCII:
After AppendQuoteToASCII()
QuoteToASCII:"\"If you can dream it, you can do it.\""

Example 2

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	x := []byte("AppendQuoteToASCII:")
	fmt.Println("Before appending...")
	fmt.Println("x:", string(x))
	fmt.Println("Length(x): ", len(x))

	// Appending quotes to the x
	x = strconv.AppendQuoteToASCII(x, `"If you can dream it, you can do it."`)
	x = strconv.AppendQuoteToASCII(x, `"Aspire to inspire before we expire."`)

	fmt.Println("After appending...")
	fmt.Println("x:", string(x))
	fmt.Println("Length(x): ", len(x))
}

Output:

Before appending...
x: AppendQuoteToASCII:
Length(x):  19
After appending...
x: AppendQuoteToASCII:"\"If you can dream it, you can do it.\"""\"Aspire to inspire before we expire.\""
Length(x):  101

Golang strconv Package »




Comments and Discussions!

Load comments ↻





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