如何将UINT64转换为焊接中的字符串
// 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
openzeppelin的
string.tostring()
接受uint256
的UINT。因此,在使用toString
之前,请将您的uint64
施放为uint256
。例如:
Openzeppelin's
String.toString()
accepts a uint ofuint256
. So before usingtoString
, cast youruint64
touint256
.For example:
例如
You would want to use abi.encodePacked to combine multiple strings
For example: