Blockchain 有用于字符串比较的函数吗

Blockchain 有用于字符串比较的函数吗,blockchain,ethereum,solidity,Blockchain,Ethereum,Solidity,函数调用中参数的类型无效。请求的从字符串存储引用到字节内存的隐式转换无效。此函数需要一个字节参数您可以使用此参数比较字符串 if(keccak256(products[i].category) != keccak256(category)) eq=false; 参考原始答案 function compareStrings (string memory a, string memory b) public view returns (bool) { return (k

函数调用中参数的类型无效。请求的从字符串存储引用到字节内存的隐式转换无效。此函数需要一个字节参数

您可以使用此参数比较字符串

    if(keccak256(products[i].category) != keccak256(category))
      eq=false;
参考原始答案

function compareStrings (string memory a, string memory b) public view returns (bool) {
    return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
}