Concatenating a Text and Nat

I just want to do some very basic stuff. How can I concatenate a Text and a number (Nat)?
Neither + nor # seem to be working. I got an exception of:

Stderr:
/home/rusznak/dfinity/count/src/count/increment_counter.mo:21.19-21.31: type error [M0096], expression of type
  Nat
cannot produce expected type
  Text
1 Like

You’ll need to convert the Nat to type Text first, you can use the Nat module in the base library:

import Nat “mo:base/Nat”;

let a = Nat.toText(10);

let b = “hello “ # a;

4 Likes

Thank you for the answer. Is there a cheatsheet similar to this somewhere?
https://solidity-by-example.org/

3 Likes

There is actually a resource very much like this on the way. Right now the tutorials on the sdk site are a great way to get familiar: https://sdk.dfinity.org/docs/developers-guide/tutorials-intro.html

I’d also recommend the education repo: https://github.com/DFINITY-Education

And some example project repos along with the Motoko base library code itself, which is a great reference, see here: https://forum.dfinity.org/t/how-to-learn-motoko-with-no-experience/1643/5?u=ori

1 Like

I also created a tutorial (inspired by enzoh superheroes repo):

Feedback, comment, constructive criticism is welcome.

2 Likes