Search code examples
soliditysmartcontractseverscale

Error with <string>.append() in ton-solidity: Different number of components on the left hand side (1) than on the right hand side (0)


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?


Solution

  • 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;