ton-solidity 中 <string>.append() 的错误:左侧 (1) 的组件数量与右侧 (0) 的组件数量不同

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

我连接 2 个字符串的代码非常简单:

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

但是我有一个错误:

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);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

怎么了?

.append() 函数修改了现有的字符串,因此没有返回任何内容。

所以你可以打电话

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

然后baseUrl会被修改。如果你想用新值设置一个新变量url,你可以做

string url = baseUrl;