{

How to convert from single character to/from string in Nim?


This tutorials explains about how to concatenate Strings in Nim language.

Nim String Concatenate example

There are multiple ways, we do string append in NIM language.

  • using & operator

    & operator appends one string into end of another string.

var str = "one "
var str1 = "two "
var result= str & str1
echo result
  • using strutils join function strutils module has join procedure that joins the openarray of elements to append

Syntax:

func join(a: openArray[string]; sep: string = ""): string {.....}

Input: array of strings sep - is an separator that appends between each string

Here is an example

import strutils;
var result=join(["one", "two", "three"], " ") 
echo result

Output:

one two three
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.