如何将UINT64转换为焊接中的字符串

发布于 2025-02-12 03:37:43 字数 449 浏览 2 评论 0原文

// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import "./Strings.sol";

contract NFTTest {

   uint64 serialNum = 1;

   string public uri;
   string public uriPrefix ="abc/";
   string public uriSuffix = ".json";

function setURI() external {
   uri = uriPrefix + Strings.toString(serialNum) + uriSuffix;
}

但是问题是我得到错误: 操作员 +与字符串存储Ref和String Memory不确定

我在做什么错。我正在使用strings.sol库。

// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import "./Strings.sol";

contract NFTTest {

   uint64 serialNum = 1;

   string public uri;
   string public uriPrefix ="abc/";
   string public uriSuffix = ".json";

function setURI() external {
   uri = uriPrefix + Strings.toString(serialNum) + uriSuffix;
}

But the issue is I get the error:
Operator + not compatible with types string storage ref and string memory

Not sure what I'm doing wrong. I'm using the Strings.sol library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉酒的小男人 2025-02-19 03:37:43

openzeppelin的string.tostring()接受uint256的UINT。因此,在使用toString之前,请将您的uint64施放为uint256

例如:

变量= string.tostring(uint256(numberinuint64));

Openzeppelin's String.toString() accepts a uint of uint256. So before using toString, cast your uint64 to uint256.

enter image description here

For example:

variable = String.toString( uint256( numberInUint64 ));

愛放△進行李 2025-02-19 03:37:43

例如

   uri = string(abi.encodePacked(uriPrefix, Strings.toString(serialNum), uriSuffix));

You would want to use abi.encodePacked to combine multiple strings

For example:

   uri = string(abi.encodePacked(uriPrefix, Strings.toString(serialNum), uriSuffix));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文