Skip to content

Commit

Permalink
Add "How do I" section.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelimion committed Jul 24, 2024
1 parent c89daa4 commit 1b46255
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions content/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,31 @@ The reason for the specific syntax was done for the following reasons:
* Virtually all slicing cases only ever require the Python/Go like semantics because Odin is a 0-index language
* Ranges in Odin are only allowed in two contexts: `case`s and `for in` loops

## How do I ...?
### Convert an integer to a string or vice versa?
```odin
package numbers_example
import "core:strconv"
main :: proc() {
// We'll shortly overwrite the part of this array that we need,
// so we use `---` to tell the compiler it doesn't have to be zero-initialized.
buf: [64]u8 = ---
// Format the integer to a string, using memory backed by `buf`.
a := 4815162342
s := strconv.itoa(buf[:], a)
// Parse it back into an integer. We assume it's a valid base-10 representation here.
// If you want to check it was parsed correctly or parse binary, octal or hexadecimal,
// look at the `parse_*` procedures.
b := strconv.atoi(s)
assert(a == b)
}
```

## Implementation
### What does the compiler use?
The compiler is written in C++ but in a very C style.
Expand Down

0 comments on commit 1b46255

Please sign in to comment.