3

Is it possible to convert string to bytes32?

For example:

contract c {  
    string public name;  
    mapping (string => bytes32) str2bytes32;  

    function test(string t) returns(bytes32){  
        name = t;  
        return str2bytes32[name];  
    }  
}  

Upon deploying this contract and calling the function test always returns 0x, no matter what string I pass in. So just wondering what the issue is. However, changing the argument type from string to bytes32 in the function and changing the variable type for name helped ensuring the return value of bytes32. Any suggestions as to why the hash map didn't work would be helpful?

jrbedard
  • 524
  • 1
  • 6
  • 15
skarred14
  • 945
  • 1
  • 9
  • 18

0 Answers0