{

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 intToStr operator

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
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.