Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare a string with a bytes32 value?

I'm trying to check that a string value is equal to a bytes32 value in Solidity, like stringValue == bytes32Value.

As you can see in:

Variable values in Truffle Debugging 1

both variables have the same content. But how can I compare them?

like image 859
David S. Avatar asked Mar 23 '26 02:03

David S.


1 Answers

See if this post helps - https://ethereum.stackexchange.com/a/9152

First, the string is read in as bytes using bytes method, which is used to perform empty string test, and then it leverages assembly method to return bytes32 representation of provided string.

Moreover, solidity documentation points to byte initialization techniques from string

like image 186
Mukul Avatar answered Mar 24 '26 14:03

Mukul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!