I have a bytes32[] array. I convert strings to bytes32 before they are added to the array as follows:
function stringToBytes32(string memory source) returns (bytes32 result) {
assembly {
result := mload(add(source, 32))
}
}
which will turn the string into a hex like 0x5468697320697320612074657374206d65737361676520746861742077696c6c, for example.
However, if the string converted into bytes32 is over 32 characters, I don't know how to turn it back into its original string over 32 characters. Using web3.toAscii
only brings back the first 32 characters.
Best Answer
This works pretty well for me. I would agree that its a little complex to encode and decode, but just run your 32 byte array through it to get a string back
Edit - Here's some added stuff. A rather hacky way, but it might work for you. I'm sure Rob will yell at this answer though