Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Created April 20, 2022 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PatrickAlphaC/3e936cb84ce72ac2964d93b44b3366a3 to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/3e936cb84ce72ac2964d93b44b3366a3 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;
contract StringConcater {
// only in 0.8.12 and above
function concatStringsNewWay() public pure returns(string memory){
string memory hiMom = "Hi Mom, ";
string memory missYou = "miss you.";
return string.concat(hiMom, missYou);
}
function concatStringsOldWay() public pure returns (string memory){
string memory hiMom = "Hi Mom, ";
string memory missYou = "miss you.";
return string(abi.encodePacked(hiMom, missYou));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment