Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function compareStringsbyBytes(string s1, string s2) public pure returns(bool)
  2. {
  3. bytes memory s1bytes = bytes(s1);
  4. bytes memory s2bytes = bytes(s2);
  5. if(s1bytes.length!=s2bytes.length) {
  6. return false;
  7. }
  8. else{
  9. for(uint i = 0;i<s1bytes.length;i++)
  10. {
  11. if(s1bytes[i] != s2bytes[i])
  12. return false;
  13. }
  14. return true;
  15. }
  16. }
  17.  
  18. function compareStringsbyBytes(string s1, string s2) public pure returns(bool){
  19. return keccak256(s1) == keccak256(s2);
  20. }
  21.  
  22. function compareStringsbyBytes(string memory s1, string memory s2) public pure returns(bool){
  23. return keccak256(abi.encodePacked(s1)) == keccak256(abi.encodePacked(s2));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement