How to compare a string with a bytes32 value?

Viewed 1644

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?

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

Related