首页 > 区块链 > 区块链 > IPP Swap孵化器/LP挖矿系统开发方案
判读字符串相等不能直接使用==这样的方法,我也搞不清为什么,很多语言都是直接支持的,只有Solidity不支持。没办法,只能自己设计个方法来实现。
function compareStr(string _str1,string _str2)public returns(bool){
if(keccak256(abi.encodePacked(_str1))==keccak256(abi.encodePacked(_str2))){
//如果二者相等,使checkResult为true
checkResult=true;
}else{
checkResult=false;
}
//返回checkResult
return checkResult;
}
对两个字符串进行哈希运算,结果一致就证明两个字符串相等。这个哈希运算有点费时,可以在这之前做个长度判断以节约点时间,达到一个平衡。改进后的方法:
function compareStr(string _str1,string _str2)public returns(bool){
if(bytes(_str1).length==bytes(_str2).length){
if(keccak256(abi.encodePacked(_str1))==keccak256(abi.encodePacked(_str2))){
retrun true;
}
}
return false;
}
IPPSWAP孵化器牛逼之处在于解解决行业六大痛点,

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70029947/viewspace-2953131/ ,如需转载,请注明出处,否则将追究法律责任。