Jun asked return not fixed – term, bashan night rain rise autumn pool

Home has been nearly a year, although occasionally homesick to step the heart of the way home, but but all kinds of realistic reasons, failed to start, perhaps the next way home can only be arranged to the next harvest of the golden season. Speaking of hometown for most people always feel is a mysterious place, always want to escape at the time, always want to return at the time of leaving, as expected human joys and sorrows are always so surprising.

Strconv package for go language

The Strconv package of the Go language mainly provides functions and methods for converting different data types to each other, which will be explained below.

package main

/*********************************************************************/
/**************** golang中strconv包相关API讲解 ***********************/
/*******************************************************************/

/*
Constants
Variables
func AppendBool(dst []byte, b bool) []byte
func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byte
func AppendInt(dst []byte, i int64, base int) []byte
func AppendQuote(dst []byte, s string) []byte
func AppendQuoteRune(dst []byte, r rune) []byte
func AppendQuoteRuneToASCII(dst []byte, r rune) []byte
func AppendQuoteRuneToGraphic(dst []byte, r rune) []byte
func AppendQuoteToASCII(dst []byte, s string) []byte
func AppendQuoteToGraphic(dst []byte, s string) []byte
func AppendUint(dst []byte, i uint64, base int) []byte
func Atoi(s string) (int, error)
func CanBackquote(s string) bool
func FormatBool(b bool) string
func FormatComplex(c complex128, fmt byte, prec, bitSize int) string
func FormatFloat(f float64, fmt byte, prec, bitSize int) string
func FormatInt(i int64, base int) string
func FormatUint(i uint64, base int) string
func IsGraphic(r rune) bool
func IsPrint(r rune) bool
func Itoa(i int) string
func ParseBool(str string) (bool, error)
func ParseComplex(s string, bitSize int) (complex128, error)
func ParseFloat(s string, bitSize int) (float64, error)
func ParseInt(s string, base int, bitSize int) (i int64, err error)
func ParseUint(s string, base int, bitSize int) (uint64, error)
func Quote(s string) string
func QuoteRune(r rune) string
func QuoteRuneToASCII(r rune) string
func QuoteRuneToGraphic(r rune) string
func QuoteToASCII(s string) string
func QuoteToGraphic(s string) string
func Unquote(s string) (string, error)
func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error)
type NumError
	func (e *NumError) Error() string
	func (e *NumError) Unwrap() error
*/

func main() {

	/**
	*AppendBool根据b的值将"true"或"false"附加到dst并返回扩展缓冲区。
	*func AppendBool(dst []byte, b bool) []byte
	*/

	/*
	b := []byte("bool:")
	b = strconv.AppendBool(b, true)
	fmt.Println(string(b))
	*/

	/**
	*AppendFloat将由FormatFloat生成的浮点数f的字符串形式附加到dst,并返回扩展缓冲区。
	*func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byte
	*/

	/*
	b32 := []byte("float32:")
	b32 = strconv.AppendFloat(b32, 3.1415926535, 'E', -1, 32)
	fmt.Println(string(b32))

	b64 := []byte("float64:")
	b64 = strconv.AppendFloat(b64, 3.1415926535, 'E', -1, 64)
	fmt.Println(string(b64))
	*/

	/**
	*AppendInt将由FormatInt生成的整数i的字符串形式附加到dst,并返回扩展缓冲区。
	*func AppendInt(dst []byte, i int64, base int) []byte
	*/

	/*
	b10 := []byte("int (base 10):")
	b10 = strconv.AppendInt(b10, -42, 10)
	fmt.Println(string(b10))

	b16 := []byte("int (base 16):")
	b16 = strconv.AppendInt(b16, -42, 16)
	fmt.Println(string(b16))
	*/

	/**
	*AppendQuote将由Quote生成的表示s的double-quoted Go字符串文字附加到dst,
	*并返回扩展缓冲区。
	*func AppendQuote(dst []byte, s string) []byte
	*/

	/*
	b := []byte("quote:")
	b = strconv.AppendQuote(b, `"Fran & Freddie's Diner"`)
	fmt.Println(string(b))
	*/

	/**
	*AppendQuoteRune将由QuoteRune生成的代表符文的single-quoted Go字符文字附加到dst,
	*并返回扩展缓冲区。
	*func AppendQuoteRune(dst []byte, r rune) []byte
	*/

	/*
	b := []byte("rune:")
	b = strconv.AppendQuoteRune(b, '☺')
	fmt.Println(string(b))
	*/

	/**
	*AppendQuoteToASCII将QuoteToASCII生成的表示s的double-quoted Go字符串文字附加到dst,
	*并返回扩展缓冲区。
	*func AppendQuoteRuneToASCII(dst []byte, r rune) []byte
	*/

	/*
	b := []byte("quote (ascii):")
	b = strconv.AppendQuoteToASCII(b, `"Fran & Freddie's Diner"`)
	fmt.Println(string(b))
	*/

	/**
	*QuoteToGraphic返回代表s的double-quoted Go字符串文字。返回的字符串保留IsGraphic定义的
	*Unicode图形字符不变,并且对非图形字符使用Go转义序列(\ t,\ n,\ xFF,\ u0100)。
	*func AppendQuoteRuneToGraphic(dst []byte, r rune) []byte
	*/

	/*
	s := strconv.QuoteToGraphic("☺")
	fmt.Println(s)

	s = strconv.QuoteToGraphic("This is a \u263a	\u000a")
	fmt.Println(s)

	s = strconv.QuoteToGraphic(`" This is a ☺ \n "`)
	fmt.Println(s)
	*/


	/**
	*AppendQuoteToASCII将QuoteToASCII生成的表示s的double-quoted Go字符串文字附加到dst,
	*并返回扩展缓冲区。
	*func AppendQuoteToASCII(dst []byte, s string) []byte
	*/

	/*
	b := []byte("quote (ascii):")
	b = strconv.AppendQuoteToASCII(b, `"Fran & Freddie's Diner"`)
	fmt.Println(string(b))
	*/

	/**
	*
	*func AppendQuoteToGraphic(dst []byte, s string) []byte
	*/


	/**
	*AppendUint将由FormatUint生成的无符号整数i的字符串形式附加到dst,然后返回扩展缓冲区。
	*func AppendUint(dst []byte, i uint64, base int) []byte
	*/

	/*
	b10 := []byte("uint (base 10):")
	b10 = strconv.AppendUint(b10, 42, 10)
	fmt.Println(string(b10))

	b16 := []byte("uint (base 16):")
	b16 = strconv.AppendUint(b16, 42, 16)
	fmt.Println(string(b16))
	*/


	/**
	*AppendUint将由FormatUint生成的无符号整数i的字符串形式附加到dst,然后返回扩展缓冲区。
	*func Atoi(s string) (int, error)
	*/

	/*
	v := "10"
	if s, err := strconv.Atoi(v); err == nil {
		fmt.Printf("%T, %v", s, s)
	}
	*/

	/**
	*CanBackquote报告字符串s是否可以不变地表示为单行反引号字符串,并且没有制表符以外的控制字符。
	*func CanBackquote(s string) bool
	*/

	/*
	fmt.Println(strconv.CanBackquote("Fran & Freddie's Diner ☺"))
	fmt.Println(strconv.CanBackquote("`can't backquote this`"))
	*/

	/**
	*FormatBool根据b的值返回"true"或"false"。
	*func FormatBool(b bool) string
	*/

	/*
	v := true
	s := strconv.FormatBool(v)
	fmt.Printf("%T, %v\n", s, s)
	*/

	/**
	*
	*func FormatComplex(c complex128, fmt byte, prec, bitSize int) string
	*/


	/**
	*根据设定的进度转换为指定的float类型
	*func FormatFloat(f float64, fmt byte, prec, bitSize int) string
	*/

	/*
	v := 3.1415926535
	s32 := strconv.FormatFloat(v, 'E', -1, 32)
	fmt.Printf("%T, %v\n", s32, s32)

	s64 := strconv.FormatFloat(v, 'E', -1, 64)
	fmt.Printf("%T, %v\n", s64, s64)
	*/

	/**
	*FormatInt以2 <= base <= 36的形式返回给定基数i的字符串表示形式。
	*结果使用小写字母'a'到'z'表示数字值> = 10。
	*func FormatInt(i int64, base int) string
	*/

	/*
	v := int64(-42)
	s10 := strconv.FormatInt(v, 10)
	fmt.Printf("%T, %v\n", s10, s10)
	s16 := strconv.FormatInt(v, 16)
	fmt.Printf("%T, %v\n", s16, s16)
	*/

	/**
	*IsGraphic报告是否通过Unicode将符文定义为图形。此类字符包括字母,标记,
	*数字,标点符号,符号和空格,来自类别L,M,N,P,S和Zs。
	*func IsGraphic(r rune) bool
	*/

	/*
	shamrock := strconv.IsGraphic('☘')
	fmt.Println(shamrock)

	a := strconv.IsGraphic('a')
	fmt.Println(a)

	bel := strconv.IsGraphic('\007')
	fmt.Println(bel)
	*/

	/**
	*IsPrint报告符文是否已定义为Go可打印的符文,其定义与unicode.IsPrint:
	*字母,数字,标点,符号和ASCII空间。
	*func IsPrint(r rune) bool
	*/

	/*
	c := strconv.IsPrint('\u263a')
	fmt.Println(c)

	bel := strconv.IsPrint('\007')
	fmt.Println(bel)
	*/

	/**
	*Itoa等效于FormatInt(int64(i),10)。
	*func Itoa(i int) string
	*/

	/*
	i := 10
	s := strconv.Itoa(i)
	fmt.Printf("%T, %v\n", s, s)
	*/

	/**
	*ParseBool返回由字符串表示的布尔值。它接受1,t,T,TRUE,true,True,0,f,F,FALSE,
	*false,False。其他任何值都将返回错误。
	*func ParseBool(str string) (bool, error)
	*/

	/*
	v := "true"
	if s, err := strconv.ParseBool(v); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	*/

	/**
	*
	*func ParseComplex(s string, bitSize int) (complex128, error)
	*/

	/**
	*ParseFloat将字符串s转换为由bitSize指定的精度的浮点数
	*func ParseFloat(s string, bitSize int) (float64, error)
	*/

	/*
	v := "3.1415926535"
	if s, err := strconv.ParseFloat(v, 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat(v, 64); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("NaN", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("nan", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("inf", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("+Inf", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("-Inf", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("-0", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseFloat("+0", 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	*/

	/**
	*ParseInt解析给定基数(0、2到36)和位大小(0到64)中的字符串s,并返回相应的值i。
	*func ParseInt(s string, base int, bitSize int) (i int64, err error)
	*/

	/*
	v32 := "-354634382"
	if s, err := strconv.ParseInt(v32, 10, 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseInt(v32, 16, 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}

	v64 := "-3546343826724305832"
	if s, err := strconv.ParseInt(v64, 10, 64); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseInt(v64, 16, 64); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	*/

	/**
	*ParseUint类似于ParseInt,但用于无符号数字。
	*func ParseUint(s string, base int, bitSize int) (uint64, error)
	*/

	/*
	v := "42"
	if s, err := strconv.ParseUint(v, 10, 32); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	if s, err := strconv.ParseUint(v, 10, 64); err == nil {
		fmt.Printf("%T, %v\n", s, s)
	}
	*/

	/**
	*引用返回一个表示s的double-quoted Go字符串文字。返回的字符串使用Go转义序列
	*(\ t,\ n,\ xFF,\ u0100)来控制字符和IsPrint定义的不可打印字符。
	*func Quote(s string) string
	*/

	/*
	s := strconv.Quote(`"Fran & Freddie's Diner	☺"`)
	fmt.Println(s)
	*/

	/**
	*QuoteRune返回代表符文的single-quoted Go字符文字。返回的字符串使用Go转义序列
	*(\ t,\ n,\ xFF,\ u0100)来控制字符和IsPrint定义的不可打印字符。
	*func QuoteRune(r rune) string
	*/

	/*
	s := strconv.QuoteRune('☺')
	fmt.Println(s)
	*/

	/**
	*QuoteRuneToASCII返回代表符文的single-quoted Go字符文字。返回的字符串对IsASCII
	*定义的非ASCII字符和不可打印的字符使用Go转义序列(\ t,\ n,\ xFF,\ u0100)。
	*func QuoteRuneToASCII(r rune) string
	*/

	/*
	s := strconv.QuoteRuneToASCII('☺')
	fmt.Println(s)
	*/

	/**
	*QuoteRuneToGraphic返回代表符文的single-quoted Go字符文字。如果符文不是IsGraphic
	*定义的Unicode图形字符,则返回的字符串将使用Go转义序列(\ t,\ n,\ xFF,\ u0100)。
	*func QuoteRuneToGraphic(r rune) string
	*/

	/*
	s := strconv.QuoteRuneToGraphic('☺')
	fmt.Println(s)

	s = strconv.QuoteRuneToGraphic('\u263a')
	fmt.Println(s)

	s = strconv.QuoteRuneToGraphic('\u000a')
	fmt.Println(s)

	s = strconv.QuoteRuneToGraphic('	') // tab character
	fmt.Println(s)
	*/

	/**
	*QuoteToASCII返回代表s的double-quoted Go字符串文字。返回的字符串对
	*IsASCII定义的非ASCII字符和不可打印的字符使用Go转义序列(\ t,\ n,\ xFF,\ u0100)。
	*func QuoteToASCII(s string) string
	*/

	/*
	s := strconv.QuoteToASCII(`"Fran & Freddie's Diner	☺"`)
	fmt.Println(s)
	*/

	/**
	*QuoteToGraphic返回代表s的double-quoted Go字符串文字。返回的字符串保留IsGraphic定义
	*的Unicode图形字符不变,并且对非图形字符使用Go转义序列(\ t,\ n,\ xFF,\ u0100)。
	*func QuoteToGraphic(s string) string
	*/

	/*
	s := strconv.QuoteToGraphic("☺")
	fmt.Println(s)
	s = strconv.QuoteToGraphic("This is a \u263a	\u000a")
	fmt.Println(s)
	s = strconv.QuoteToGraphic(`" This is a ☺ \n "`)
	fmt.Println(s)
	*/

	/**
	*Unquote将s解释为single-quoted,double-quoted或带反引号的Go字符串文字,
        *并返回用s引起引用的字符串值。
	*(如果s是single-quoted,则它将是Go字符文字; Unquote返回相应的one-character字符串。)
	*func Unquote(s string) (string, error)
	*/

	/*
	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)
	*/

	/**
	*UnquoteChar解码转义的字符串或由字符串s表示的字符文字中的第一个字符或字节。它返回四个值
	*func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error)
	*/

	/*
	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)
	*/

	/**********************************************************************/
	/**************** NumError中相关方法讲解 ***************************/
	/********************************************************************/

	/**
	*NumError记录转换失败
	*func (e *NumError) Error() string
	*/

	/*
	str := "Not a number"
	if _, err := strconv.ParseFloat(str, 64); err != nil {
		e := err.(*strconv.NumError)
		fmt.Println("Func:", e.Func)
		fmt.Println("Num:", e.Num)
		fmt.Println("Err:", e.Err)
		fmt.Println(err)
	}
	*/


	/**
	*使用 Unwrap 方法可以获取一个错误中包含的另外一个错误
	*func (e *NumError) Unwrap() error
	*/

}
Copy the code

summary

The strconv section covers a lot of information, but there are only a few types of conversion that are commonly used. This section is strongly recommended because it is not too difficult to master.