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