Skip to content

Instantly share code, notes, and snippets.

@tempe-techie
Created June 30, 2022 15:49
Show Gist options
  • Save tempe-techie/2592fd5f9c9ea7b003cd942e48d40765 to your computer and use it in GitHub Desktop.
Save tempe-techie/2592fd5f9c9ea7b003cd942e48d40765 to your computer and use it in GitHub Desktop.
Solidity helpers
// 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