-
-
Save crazyrabbitLTC/08707f25f9fee9e13b4e00e670da347c to your computer and use it in GitHub Desktop.
Ethereum/Solidity toLower() equivalent, to transform strings to lowercase
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
pragma solidity ^0.4.11; | |
contract StringToLower { | |
function _toLower(string str) internal returns (string) { | |
bytes memory bStr = bytes(str); | |
bytes memory bLower = new bytes(bStr.length); | |
for (uint i = 0; i < bStr.length; i++) { | |
// Uppercase character... | |
if ((bStr[i] >= 65) && (bStr[i] <= 90)) { | |
// So we add 32 to make it lowercase | |
bLower[i] = bytes1(int(bStr[i]) + 32); | |
} else { | |
bLower[i] = bStr[i]; | |
} | |
} | |
return string(bLower); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original code by: https://gist.github.com/ottodevs/c43d0a8b4b891ac2da675f825b1d1dbf