Created
December 26, 2017 02:17
-
-
Save lemonlatte/f78482c32058f287d3677951e1c09e61 to your computer and use it in GitHub Desktop.
Ethereum Libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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