Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
go

What is the strconv.AppendQuoteRuneToGraphic() function in Go?

Maria Elijah

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The AppendQuoteRuneToGraphic() function of the strconv package is used to append the single-quoted Go character literal that represents r (as generated by the QuoteRuneToGraphic() function) to dst and then return the extended buffer.

Note: The parameter dst is of type []byte and r is of the type rune.

Syntax

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

Parameter values

  • dst: This is a byte array to which the single-quoted character is to be appended.
  • r: This is the rune character that is to be appended.

Return value

The AppendQuoteRuneToGraphic() function returns the extended buffer after appending the single-quoted character to dst.

Example

The following code shows us how to implement the AppendQuoteRuneToGraphic() function in Golang.

// Using strconv.AppendQuoteRuneToGraphic() Function
package main
import (
"fmt"
"strconv"
)
func main() {
x := []byte("QuoteRuneToGraphic:")
fmt.Println("Orignal value before AppendQuoteRuneToGraphic()", string(x))
fmt.Println()
// Append a character (rune 108 is the Unicode of l)
x = strconv.AppendQuoteRuneToGraphic(x, 108)
fmt.Println("The new Value after AppendQuoteRuneToGraphic()", string(x))
fmt.Println()
// Append emoji
x = strconv.AppendQuoteRuneToGraphic(x, 'πŸ™‰')
fmt.Println("The new Value after AppendQuoteRuneToGraphic()", string(x))
fmt.Println()
// Append emoji
x = strconv.AppendQuoteRuneToGraphic(x, 'πŸ™Š')
// Append a character (rune 95 is the Unicode of _)
x = strconv.AppendQuoteRuneToGraphic(x, 95)
fmt.Println("The new Value after AppendQuoteRuneToGraphic()", string(x))
}

Explanation

  • Line 4: We add the main package.
  • Lines 6–9: We import the necessary packages in the Golang project.
  • Lines 11–21: We define the main() function. Then, we define the variable r of type rune, assign a value to it, and pass it to the AppendQuoteRuneToGraphic() function. This returns a single-quoted Go character literal that represents the given rune value. Finally, we display the result.

Note: All the values assigned to the variable x are appended to the dst of type []byte.

RELATED TAGS

communitycreator
go

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring