Skip to content

Instantly share code, notes, and snippets.

@lemonlatte
Created December 26, 2017 02:17
Show Gist options
  • Save lemonlatte/f78482c32058f287d3677951e1c09e61 to your computer and use it in GitHub Desktop.
Save lemonlatte/f78482c32058f287d3677951e1c09e61 to your computer and use it in GitHub Desktop.
Ethereum Libraries
library strings {
function bytes32ToString(bytes32 s) returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = s[j];
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment