ADVERTISEMENT
ADVERTISEMENT

Golang strconv.AppendQuoteRune() Function with Examples

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

strconv.AppendQuoteRune()

The AppendQuoteRune() function is an inbuilt function of the strconv package which is used to append the single-quoted Go character literal representing the r (as generated by QuoteRune() function), to dst and returns the extended buffer. Where dst is the first parameter of []byte type and r is the second parameter of rune type.

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

Syntax:

func AppendQuoteRune(dst []byte, r rune) []byte

Parameter(s):

  • dst : A byte array (or byte slices) in which we have to append the single-quoted character literal.
  • r : Rune character to be appended.

Return Value:

The return type of AppendQuoteRune() function is a []byte, it returns the extended buffer after appending the single-quoted character.

Example 1:

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

package main

import (
	"fmt"
	"strconv"
)

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

	// Appending a character
	// [rune 97 - Unicode of a]
	x = strconv.AppendQuoteRune(x, 97)
	fmt.Println("After AppendQuoteRune()")
	fmt.Println(string(x))

	// Appending an emotion (emoji)
	x = strconv.AppendQuoteRune(x, '🥰')
	fmt.Println("After AppendQuoteRune()")
	fmt.Println(string(x))
}

Output:

Before AppendQuoteRune()
QuoteRune:
After AppendQuoteRune()
QuoteRune:'a'
After AppendQuoteRune()
QuoteRune:'a''🥰'

Example 2:

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

package main

import (
	"fmt"
	"strconv"
)

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

	// Appending characters & monkey facse
	x = strconv.AppendQuoteRune(x, 97)
	x = strconv.AppendQuoteRune(x, '🙈')
	x = strconv.AppendQuoteRune(x, '🙉')
	x = strconv.AppendQuoteRune(x, '🙊')

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

Output:

Before appending...
x: QuoteRune:
Length(x):  10
After appending...
x: QuoteRune:'a''🙈''🙉''🙊'
Length(x):  31

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.