doc.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package strconv implements conversions to and from string representations
  5. // of basic data types.
  6. //
  7. // Numeric Conversions
  8. //
  9. // The most common numeric conversions are Atoi (string to int) and Itoa (int to string).
  10. //
  11. // i, err := strconv.Atoi("-42")
  12. // s := strconv.Itoa(-42)
  13. //
  14. // These assume decimal and the Go int type.
  15. //
  16. // ParseBool, ParseFloat, ParseInt, and ParseUint convert strings to values:
  17. //
  18. // b, err := strconv.ParseBool("true")
  19. // f, err := strconv.ParseFloat("3.1415", 64)
  20. // i, err := strconv.ParseInt("-42", 10, 64)
  21. // u, err := strconv.ParseUint("42", 10, 64)
  22. //
  23. // The parse functions return the widest type (float64, int64, and uint64),
  24. // but if the size argument specifies a narrower width the result can be
  25. // converted to that narrower type without data loss:
  26. //
  27. // s := "2147483647" // biggest int32
  28. // i64, err := strconv.ParseInt(s, 10, 32)
  29. // ...
  30. // i := int32(i64)
  31. //
  32. // FormatBool, FormatFloat, FormatInt, and FormatUint convert values to strings:
  33. //
  34. // s := strconv.FormatBool(true)
  35. // s := strconv.FormatFloat(3.1415, 'E', -1, 64)
  36. // s := strconv.FormatInt(-42, 16)
  37. // s := strconv.FormatUint(42, 16)
  38. //
  39. // AppendBool, AppendFloat, AppendInt, and AppendUint are similar but
  40. // append the formatted value to a destination slice.
  41. //
  42. // String Conversions
  43. //
  44. // Quote and QuoteToASCII convert strings to quoted Go string literals.
  45. // The latter guarantees that the result is an ASCII string, by escaping
  46. // any non-ASCII Unicode with \u:
  47. //
  48. // q := strconv.Quote("Hello, 世界")
  49. // q := strconv.QuoteToASCII("Hello, 世界")
  50. //
  51. // QuoteRune and QuoteRuneToASCII are similar but accept runes and
  52. // return quoted Go rune literals.
  53. //
  54. // Unquote and UnquoteChar unquote Go string and rune literals.
  55. //
  56. package strconv