ADVERTISEMENT
ADVERTISEMENT

Golang strconv.AppendQuote() Function with Examples

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

strconv.AppendQuote()

The AppendQuote() 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 Quote() 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 AppendQuote(dst []byte, s string) []byte

Parameter(s):

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

Return Value:

The return type of AppendQuote() 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.AppendQuote() Function

package main

import (
	"fmt"
	"strconv"
)

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

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

Output:

Before AppendQuote()
Quote:
After AppendQuote()
Quote:"\"If you can dream it, you can do it.\""

Example 2:

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

package main

import (
	"fmt"
	"strconv"
)

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

	// Appending quotes to the x
	x = strconv.AppendQuote(x, `"If you can dream it, you can do it."`)
	x = strconv.AppendQuote(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: Quote:
Length(x):  6
After appending...
x: Quote:"\"If you can dream it, you can do it.\"""\"Aspire to inspire before we expire.\""
Length(x):  88

Golang strconv Package »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.