Standard library / unicode/utf8
utf8.DecodeLastRuneInString()
Decodes the last rune and width from a string; invalid trailing encoding consumes one byte; empty input has width zero. Expected stdout: 'é 2\n'.
Formal Syntax & Structure
go syntaxgo
func DecodeLastRuneInString(s string) (r rune, size int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
Return Value
(r rune, size int)
Decodes the last rune and width from a string; 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.DecodeLastRuneInString("aé") fmt.Println(string(r), n)}