github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/strconv/doc.go (about) 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 // パッケージ strconv は基本データ型の文字列表現への変換を実装します。 6 // 7 // # 数値の変換 8 // 9 // 最も一般的な数値の変換は Atoi (文字列から整数へ) と Itoa (整数から文字列へ) です。 10 // 11 // i, err := strconv.Atoi("-42") 12 // s := strconv.Itoa(-42) 13 // 14 // これらは10進数とGoのint型を仮定しています。 15 // 16 // [ParseBool]、[ParseFloat]、[ParseInt]、および [ParseUint] は文字列を値に変換します: 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 // パース関数は最も広い型(float64、int64、およびuint64)を返しますが、サイズ引数が 24 // より狭い幅を指定している場合、結果はその狭い型にデータの損失なく変換できます: 25 // 26 // s := "2147483647" // 最大のint32 27 // i64, err := strconv.ParseInt(s, 10, 32) 28 // ... 29 // i := int32(i64) 30 // 31 // [FormatBool]、[FormatFloat]、[FormatInt]、および [FormatUint] は値を文字列に変換します: 32 // 33 // s := strconv.FormatBool(true) 34 // s := strconv.FormatFloat(3.1415, 'E', -1, 64) 35 // s := strconv.FormatInt(-42, 16) 36 // s := strconv.FormatUint(42, 16) 37 // 38 // [AppendBool]、[AppendFloat]、[AppendInt]、および [AppendUint] は類似していますが、 39 // フォーマットされた値を宛先スライスに追加します。 40 // 41 // # 文字列の変換 42 // 43 // [Quote] および [QuoteToASCII] は文字列をクォートされたGo文字リテラルに変換します。 44 // 後者は非ASCII Unicodeを \u でエスケープして、結果がASCII文字列であることを保証します: 45 // 46 // q := strconv.Quote("Hello, 世界") 47 // q := strconv.QuoteToASCII("Hello, 世界") 48 // 49 // [QuoteRune] および [QuoteRuneToASCII] は類似していますが、runeを受け入れて、 50 // クォートされたGo runeリテラルを返します。 51 // 52 // [Unquote] および [UnquoteChar] はGo文字列およびruneリテラルのクォートを解除します。 53 package strconv