-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs/howto: use strconv.Atoi to convert string to int
This adds a Commented CUE guide demonstrating how to use the built-in function strconv.Atoi to convert a string representation of an int to the underlying int. Preview-Path: /docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/ Signed-off-by: Jonathan Matthews <[email protected]> Change-Id: I72a43c0d6b122688fcb287ea5e721d82f8ea44d9 Dispatch-Trailer: {"type":"trybot","CL":1174211,"patchset":7,"ref":"refs/changes/11/1174211/7","targetBranch":"alpha"}
- Loading branch information
1 parent
d559efe
commit 471d6b9
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...s/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected]/pkg/strconv#Atoi) | ||
is a base-10 convenience wrapper around the built-in function | ||
[`strconv.ParseInt`](https://pkg.go.dev/cuelang.org/[email protected]/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 |
18 changes: 18 additions & 0 deletions
18
...ocs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/gen_cache.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ent/docs/howto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/page.cue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package site | ||
|
||
content: docs: howto: "use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints": {} |
53 changes: 53 additions & 0 deletions
53
...owto/use-the-built-in-function-strconv-atoi-to-convert-strings-to-ints/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected]/pkg/strconv#Atoi) | ||
is a base-10 convenience wrapper around the built-in function | ||
[`strconv.ParseInt`](https://pkg.go.dev/cuelang.org/[email protected]/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 |