Argument error when concatenting string with variables in elixir

1.8k views Asked by At

Hi I am trying the String Concatenation operation in elixir. My code is as follows:

iex(1)> name="SHubham Agiwal"
        "SHubham Agiwal"
iex(2)> age =16
         16
iex(5)> "Hello" <> name <> "World" 
         "HelloSHubham AgiwalWorld"
iex(7)> "Hello" <> name <> "World" <>age
         ** (ArgumentError) argument error

As you can see, when I try to concat it with a single variable namely name, it gives me the output as HelloSHubham AgiwalWorld. But when I try to concat it with variables name and age I get Argument error. Can somebody let me know why I am getting this error?

1

There are 1 answers

2
bitwalker On BEST ANSWER

The problem is that age is not a binary. You can use interpolation instead for this, like "#{age}".