Skip to content

Instantly share code, notes, and snippets.

@TehilaFavourite
Last active June 27, 2023 13:35
Show Gist options
  • Save TehilaFavourite/fab60948f6d20ac7b2d90a597767f7e0 to your computer and use it in GitHub Desktop.
Save TehilaFavourite/fab60948f6d20ac7b2d90a597767f7e0 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
library StringUtils {
function concatenate(string memory a, string memory b) internal pure returns (string memory) {
return string(abi.encodePacked(a, b));
}
function getLength(string memory str) internal pure returns (uint256) {
return bytes(str).length;
}
}
contract MyContract {
function performStringOperations(string memory a, string memory b) public pure returns (string memory, uint256) {
string memory result = StringUtils.concatenate(a,b); // Using the concatenate() function from the StringUtils library
uint256 length = StringUtils.getLength(result); // Using the getLength() function from the StringUtils library
return (result, length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment