My code for concatenating 2 strings is pretty simple:

string baseUrl = "http://localhost:8080/";
string url = baseUrl.append(url_secret);

But I have got an error:

Error: Different number of components on the left hand side (1) than on the right hand side (0).
   --> test.sol:156:9:
    |
156 |         string url = baseUrl.append(url_secret);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What is wrong?

1

There are 1 best solutions below

0
frozen On BEST ANSWER

The .append() function modifies the existing string, so nothing is returned.

So you can just call

string baseUrl = "http://localhost:8080/";
baseUrl.append(url_secret);

and then baseUrl will be modified. If you want to set a new variable url with the new value, you can do

string url = baseUrl;