Created
June 30, 2022 15:49
-
-
Save tempe-techie/2592fd5f9c9ea7b003cd942e48d40765 to your computer and use it in GitHub Desktop.
Solidity helpers
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
// SPDX-License-Identifier: GPL-3.0-or-later | |
pragma solidity ^0.8.6; | |
contract Helpers { | |
// slice string | |
function getSlice(uint256 begin, uint256 end, string memory text) internal pure returns (string memory) { | |
bytes memory a = new bytes(end-begin+1); | |
for(uint i=0;i<=end-begin;i++){ | |
a[i] = bytes(text)[i+begin-1]; | |
} | |
return string(a); | |
} | |
// convert string to uint8 (numbers 0-9) | |
function stringToUint8(string memory numString) public pure returns(uint8) { | |
return uint8(bytes(numString)[0])-48; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment