pragma solidity ^0.8.0;
contract ExampleApp {
string[] myArray;
function add(string memory x) public {
myArray.push(x);
}
function del(string memory x) public {
for (uint j = 0; j < myArray.length; j++) {
if (keccak256(abi.encodePacked(myArray[j])) == keccak256(abi.encodePacked(x))) {
delete myArray[j];
}
}
}
function show() public view returns (uint256, string memory) {
string memory str;
for (uint j = 0; j < myArray.length; j++) {
str = string(abi.encodePacked(str, myArray[j]));
}
return(myArray.length,str);
}
}
合约中实现数组的删减,从合约中删除数据
最新推荐文章于 2023-02-15 16:35:21 发布