Nim example - Convert String to/from the Int
This tutorials explains about convert String to int and int to string in Nim language with examples.
How to convert String to Int in Nim
parseInt in strutils module convert given string to integer. It throws an ValueError if string is invalid number.
Here is an example
import strutils
const value = parseInt("12")
echo typeof(value) # int
echo value # 12
How to convert Int to String in Nim
Multiple ways we can convert int to string in nim.
- use $ operator
$ is a toString() operator that converts any type to String.
Here is an example
import strutils
const number=11
let str = $number
echo typeof(str) # string
echo str # 11
- use
strutils intToStroperator
strutils intToStr function convert int to string
Here is an example
import strutils
const number=11
let str = intToStr(number)
echo typeof(str) # string
echo str # 11
