Standard library / fmt
fmt.Appendf()
Appends formatted bytes to the destination slice b and returns the resulting slice; retain the returned value because growth can allocate. Format-directed output. Expected stdout: '"id:009"\n'.
Formal Syntax & Structure
go syntaxgo
func Appendf(b []byte, format string, a ...any) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| b | []byte | Destination byte slice; existing prefix is preserved. |
| format | string | Format string containing literal text and formatting or scanning directives. |
| a | ...any | Values consumed by formatting; may be empty. |
Return Value
[]byte
Formatted bytes including the original prefix.
Working Example
Example Snippetgo
package main
import ( "fmt")
func main() { b := []byte("id:") b = fmt.Appendf(b, "%03d", 9) fmt.Printf("%q\n", b)}