GO語言"strconv"包中"UnquoteChar"函數的用法及代碼示例。
用法:
func UnquoteChar(s string, quote byte)(value rune, multibyte bool, tail string, err error)
UnquoteChar 解碼轉義字符串或由字符串 s 表示的字符文字中的第一個字符或字節。它返回四個值:
1) value, the decoded Unicode code point or byte value; 2) multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation; 3) tail, the remainder of the string after the character; and 4) an error that will be nil if the character is syntactically valid.
第二個參數 quote 指定被解析的文字類型,因此允許使用哪個轉義的引號字符。如果設置為單引號,則允許序列 \' 並且不允許未轉義的 '。如果設置為雙引號,則允許 \" 而不允許未轉義的 "。如果設置為零,則不允許任何轉義,並允許兩個引號字符都未轉義。
例子:
package main
import (
"fmt"
"log"
"strconv"
)
func main() {
v, mb, t, err := strconv.UnquoteChar(`\"Fran & Freddie's Diner\"`, '"')
if err != nil {
log.Fatal(err)
}
fmt.Println("value:", string(v))
fmt.Println("multibyte:", mb)
fmt.Println("tail:", t)
}
輸出:
value: " multibyte: false tail: Fran & Freddie's Diner\"
相關用法
- GO Unquote用法及代碼示例
- GO Unmarshal用法及代碼示例
- GO UnaryOp用法及代碼示例
- GO Unsetenv用法及代碼示例
- GO Unwrap用法及代碼示例
- GO UnixMilli用法及代碼示例
- GO UnescapeString用法及代碼示例
- GO Unix用法及代碼示例
- GO UnixMicro用法及代碼示例
- GO UDPConn.WriteTo用法及代碼示例
- GO URL.Hostname用法及代碼示例
- GO URL.EscapedPath用法及代碼示例
- GO URL.Port用法及代碼示例
- GO URL.ResolveReference用法及代碼示例
- GO URL.Query用法及代碼示例
- GO URL.Redacted用法及代碼示例
- GO URL.Parse用法及代碼示例
- GO URL.String用法及代碼示例
- GO URL.UnmarshalBinary用法及代碼示例
- GO URL.EscapedFragment用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 UnquoteChar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。