diff --git a/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/en.md b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/en.md new file mode 100644 index 000000000..d00748eed --- /dev/null +++ b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/en.md @@ -0,0 +1,52 @@ +--- +title: Using the built-in function "strconv.Atoi" to convert strings to ints +tags: +- commented cue +- encodings +authors: +- jpluscplusm +toc_hide: true +--- + +This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) +demonstrates how to use the built-in function +[`strconv.Atoi`](https://pkg.go.dev/cuelang.org/go/pkg/strconv#Atoi) +to convert a string representation of an int to the number itself, using base +10. + +{{{with code "en" "cc"}}} +exec cue export +cmp stdout out +-- file.cue -- +package example + +import "strconv" + +"0": strconv.Atoi("0") +"1": strconv.Atoi("1") +"10": strconv.Atoi("10") +"42": strconv.Atoi("42") +"-42": strconv.Atoi("-42") +"050": strconv.Atoi("050") +"-050": strconv.Atoi("-050") +"00012345": strconv.Atoi("00012345") +-- out -- +{ + "0": 0, + "1": 1, + "10": 10, + "42": 42, + "-42": -42, + "050": 50, + "-050": -50, + "00012345": 12345 +} +{{{end}}} + +## Related content + +- [`strconv.Atoi`](https://pkg.go.dev/cuelang.org/go@v0.7.0/pkg/strconv#Atoi) + is a base-10 convenience wrapper around the built-in function + [`strconv.ParseInt`](https://pkg.go.dev/cuelang.org/go@v0.7.0/pkg/strconv#ParseInt), + which can perform conversions with custom bases and bit widths +- The [`strconv`](https://pkg.go.dev/cuelang.org/go/pkg/strconv) built-in package diff --git a/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/gen_cache.cue b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/gen_cache.cue new file mode 100644 index 000000000..ad0988d8e --- /dev/null +++ b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/gen_cache.cue @@ -0,0 +1,18 @@ +package site +{ + content: { + docs: { + howto: { + "use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints": { + page: { + cache: { + code: { + cc: "kpzS0EdTgXLpgY70txNtMTwIjplDxaGKmtIaFTePj+M=" + } + } + } + } + } + } + } +} diff --git a/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/page.cue b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/page.cue new file mode 100644 index 000000000..274c33472 --- /dev/null +++ b/content/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/page.cue @@ -0,0 +1,3 @@ +package site + +content: docs: howto: "use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints": {} diff --git a/hugo/content/en/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/index.md b/hugo/content/en/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/index.md new file mode 100644 index 000000000..168eb5e21 --- /dev/null +++ b/hugo/content/en/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/index.md @@ -0,0 +1,53 @@ +--- +title: Using the built-in function "strconv.Atoi" to convert strings to ints +tags: +- commented cue +- encodings +authors: +- jpluscplusm +toc_hide: true +--- + +This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) +demonstrates how to use the built-in function +[`strconv.Atoi`](https://pkg.go.dev/cuelang.org/go/pkg/strconv#Atoi) +to convert a string representation of an int to the number itself, using base +10. + +{{< code-tabs >}} +{{< code-tab name="file.cue" language="cue" area="top-left" >}} +package example + +import "strconv" + +"0": strconv.Atoi("0") +"1": strconv.Atoi("1") +"10": strconv.Atoi("10") +"42": strconv.Atoi("42") +"-42": strconv.Atoi("-42") +"050": strconv.Atoi("050") +"-050": strconv.Atoi("-050") +"00012345": strconv.Atoi("00012345") +{{< /code-tab >}} +{{< code-tab name="TERMINAL" language="" type="terminal" area="top-right" >}} +$ cue export +{ + "0": 0, + "1": 1, + "10": 10, + "42": 42, + "-42": -42, + "050": 50, + "-050": -50, + "00012345": 12345 +} +{{< /code-tab >}} +{{< /code-tabs >}} + +## Related content + +- [`strconv.Atoi`](https://pkg.go.dev/cuelang.org/go@v0.7.0/pkg/strconv#Atoi) + is a base-10 convenience wrapper around the built-in function + [`strconv.ParseInt`](https://pkg.go.dev/cuelang.org/go@v0.7.0/pkg/strconv#ParseInt), + which can perform conversions with custom bases and bit widths +- The [`strconv`](https://pkg.go.dev/cuelang.org/go/pkg/strconv) built-in package