當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO AppendRune用法及代碼示例

GO語言"unicode/utf8"包中"AppendRune"函數的用法及代碼示例。

用法:

func AppendRune(p []byte, r rune) []byte

AppendRune 將 r 的 UTF-8 編碼附加到 p 的末尾並返回擴展緩衝區。如果符文超出範圍,則附加RuneError的編碼

例子:

package main

import (
    "fmt"
    "unicode/utf8"
)

func main() {
    buf1 := utf8.AppendRune(nil, 0x10000)
    buf2 := utf8.AppendRune([]byte("init"), 0x10000)
    fmt.Println(string(buf1))
    fmt.Println(string(buf2))
}

輸出:

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 AppendRune。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。