Skip to content

Instantly share code, notes, and snippets.

@ottodevs
Forked from thomasmaclean/StringToLower.sol
Created September 26, 2017 11:22
Show Gist options
  • Save ottodevs/c43d0a8b4b891ac2da675f825b1d1dbf to your computer and use it in GitHub Desktop.
Save ottodevs/c43d0a8b4b891ac2da675f825b1d1dbf to your computer and use it in GitHub Desktop.

Revisions

  1. @thomasmaclean thomasmaclean revised this gist Sep 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion StringToLower.sol
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    pragma solidity ^0.4.11;

    contract StringToLower {
    function _toLower(string str) internal returns (string) {
    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++) {
  2. @thomasmaclean thomasmaclean created this gist Sep 12, 2017.
    18 changes: 18 additions & 0 deletions StringToLower.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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);
    }
    }