GO語言"encoding/hex"包中"DecodeString"函數的用法及代碼示例。
用法:
func DecodeString(s string)([]byte, error)
DecodeString 返回十六進製字符串 s 表示的字節。
DecodeString 期望 src 僅包含十六進製字符,並且 src 具有偶數長度。如果輸入格式錯誤,DecodeString 返回錯誤前解碼的字節。
例子:
package main
import (
"encoding/hex"
"fmt"
"log"
)
func main() {
const s = "48656c6c6f20476f7068657221"
decoded, err := hex.DecodeString(s)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", decoded)
}
輸出:
Hello Gopher!
相關用法
- GO DecodeLastRuneInString用法及代碼示例
- GO Decoder.Token用法及代碼示例
- GO Decoder.Decode用法及代碼示例
- GO DecodeRuneInString用法及代碼示例
- GO DecodeRune用法及代碼示例
- GO Decode用法及代碼示例
- GO Decoder用法及代碼示例
- GO DecodeLastRune用法及代碼示例
- GO DumpResponse用法及代碼示例
- GO DB.QueryRowContext用法及代碼示例
- GO Date用法及代碼示例
- GO DB.ExecContext用法及代碼示例
- GO Dial用法及代碼示例
- GO DB.BeginTx用法及代碼示例
- GO DumpRequest用法及代碼示例
- GO Drawer用法及代碼示例
- GO Duration.Hours用法及代碼示例
- GO Duration.Round用法及代碼示例
- GO DumpRequestOut用法及代碼示例
- GO Duration用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 DecodeString。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。