Standard library / unicode/utf8
utf8.DecodeLastRune()
Decodes the last rune and width from bytes; invalid trailing encoding consumes one byte; empty input has width zero. Expected stdout: 'é 2\n'.
Formal Syntax & Structure
go syntaxgo
func DecodeLastRune(p []byte) (r rune, size int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | []byte | Byte sequence or destination buffer, as specified. |
Return Value
(r rune, size int)
Decodes the last rune and width from bytes; invalid trailing encoding consumes one byte; empty input has width zero.
Working Example
Example Snippetgo
package main
import ( "fmt" "unicode/utf8")
func main() { r, n := utf8.DecodeLastRune([]byte("aé")) fmt.Println(string(r), n)}