GO語言"strconv"包中"Unquote"函數的用法及代碼示例。
用法:
func Unquote(s string)(string, error)
Unquote 將 s 解釋為單引號、雙引號或反引號 Go 字符串文字,返回 s 引用的字符串值。 (如果 s 是單引號,它將是 Go 字符文字;取消引用返回相應的 one-character 字符串。)
例子:
package main
import (
"fmt"
"strconv"
)
func main() {
s, err := strconv.Unquote("You can't unquote a string without quotes")
fmt.Printf("%q, %v\n", s, err)
s, err = strconv.Unquote("\"The string must be either double-quoted\"")
fmt.Printf("%q, %v\n", s, err)
s, err = strconv.Unquote("`or backquoted.`")
fmt.Printf("%q, %v\n", s, err)
s, err = strconv.Unquote("'\u263a'") // single character only allowed in single quotes
fmt.Printf("%q, %v\n", s, err)
s, err = strconv.Unquote("'\u2639\u2639'")
fmt.Printf("%q, %v\n", s, err)
}
輸出:
"", invalid syntax "The string must be either double-quoted", <nil> "or backquoted.", <nil> "☺", <nil> "", invalid syntax
相關用法
- GO UnquoteChar用法及代碼示例
- 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大神的英文原創作品 Unquote。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。