
Nim: Concatenating strings
Concatenating strings is one of those topics where for any given language there’s a nearly infinite way to achieve the end result. Though typically there will be one or two approaches that are deemed more idiomatic. Here’s a couple of the more common approaches within Nim
var a = "This"
a.add(" is a string")
echo "a is now: ", a
# a is now: This is a string
var
b = "This"
c " is a string"
echo "concat: ", b & c
# concat: This is a string
You can also import strutils
to use some functions that will look familiar from other languages:
# calling as a method on an array:
import strutils
echo @["a", "b", "c"].join(" ")
# a b c
# or as a function:
echo join(@["a", "b", "c"], "xx")
# axxbxxc
Published: 21/03/2022
Hi, I'm Glenn! 👋
I've spent most of my career working with or at startups. You'll usually find me working in Product leadership roles, on an advisory board, or maybe as an early investor.
I've been the VP of Product & GTM @ Ockam. I led the Terraform product team @ HashiCorp, where we launched Terraform 1.0, Terraform Cloud, and a whole host of amazing capabilities that set the stage for a successful IPO. Prior to that I was part of the Startup Team @ AWS, and earlier still an early employee @ Heroku. I've also invested in a couple of dozen early stage startups.
I've spent most of my career working with or at startups. You'll usually find me working in Product leadership roles, on an advisory board, or maybe as an early investor.
I've been the VP of Product & GTM @ Ockam. I led the Terraform product team @ HashiCorp, where we launched Terraform 1.0, Terraform Cloud, and a whole host of amazing capabilities that set the stage for a successful IPO. Prior to that I was part of the Startup Team @ AWS, and earlier still an early employee @ Heroku. I've also invested in a couple of dozen early stage startups.