Skip to content

Commit

Permalink
Create StringUtils.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 16, 2024
1 parent 3135b7f commit 3292762
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.8.0;

library StringUtils {
function concat(string memory _a, string memory _b) internal pure returns (string memory) {
return string(abi.encodePacked(_a, _b));
}

function substring(string memory _str, uint256 _start, uint256 _end) internal pure returns (string memory) {
bytes memory strBytes = bytes(_str);
bytes memory result = new bytes(_end - _start);
for (uint256 i = _start; i < _end; i++) {
result[i - _start] = strBytes[i];
}
return string(result);
}

function compare(string memory _a, string memory _b) internal pure returns (bool) {
return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b));
}
}

0 comments on commit 3292762

Please sign in to comment.