1

Question in the title, how to concatenate 2 strings in Solidity?

Googled and searched here but no luck.

Please help, Thanks

user610620
  • 1,508
  • 6
  • 24
  • 52

2 Answers2

2

With solidity 0.8.12 you can just do string.concat like so:

   function strConcat(string memory one, string memory two) external returns(string memory) {
        return  string.concat(one, two);
    }

Also, see this: How to concatenate strings in solidity?

Hope this helps!

Olivier Demeaux
  • 1,957
  • 2
  • 8
  • 16
0

strings can concatenated by

abi.encodePacked(firstString, secondString)

ERC721 uses above concatenation method.

function strConcat(string calldata firstString, string calldata secondString) external pure returns (string memory) {
        return string(abi.encodePacked(firstString, secondString));
    }