5
solidity | 拼接两个 string
source link: https://benpaodewoniu.github.io/2022/07/08/solidity45/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
solidity | 拼接两个 string
拼接字符串。
这里并没有使用 openzeppelin
提供的方法,而是,使用了原始的写法,直接调用就好了。
function strConcat(string memory _a, string memory _b) public pure returns (string memory){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory ret = new string(_ba.length + _bb.length);
bytes memory bret = bytes(ret);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) bret[k++] = _ba[i];
for (uint i = 0; i < _bb.length; i++) bret[k++] = _bb[i];
return string(ret);
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK