Skip to content

Instantly share code, notes, and snippets.

@davidhq
Forked from PatrickAlphaC/StringConcater.sol
Created April 22, 2022 19:37
Show Gist options
  • Save davidhq/4fbc8c6fb7c4513684ba9e542cddd4f6 to your computer and use it in GitHub Desktop.
Save davidhq/4fbc8c6fb7c4513684ba9e542cddd4f6 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