【问题标题】:Error with <string>.append() in ton-solidity: Different number of components on the left hand side (1) than on the right hand side (0)ton-solidity 中的 <string>.append() 出错:左侧 (1) 与右侧 (0) 的组件数量不同
【发布时间】:2021-08-28 14:24:53
【问题描述】:

我用于连接 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);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

怎么了?

【问题讨论】:

  • 建议使用string(abi.encodePacked(a, b)) 连接两个字符串以提高gas 成本。
  • 错误:不支持的函数调用

标签: solidity smartcontracts ton


【解决方案1】:

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

所以你可以打电话

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

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

string url = baseUrl;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多