Skip to content

Instantly share code, notes, and snippets.

@Chanutg
Created April 12, 2019 10:41
Show Gist options
  • Save Chanutg/fe3a2871aaa68c49955a9a5453785be2 to your computer and use it in GitHub Desktop.
Save Chanutg/fe3a2871aaa68c49955a9a5453785be2 to your computer and use it in GitHub Desktop.
Concat
function concat(string memory _base, string memory _value) internal pure returns (string memory) {
bytes memory _baseBytes = bytes(_base);
bytes memory _valueBytes = bytes(_value);
string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);
bytes memory _newValue = bytes(_tmpValue);
uint i;
uint j;
for(i=0; i<_baseBytes.length; i++) {
_newValue[j++] = _baseBytes[i];
}
for(i=0; i<_valueBytes.length; i++) {
_newValue[j++] = _valueBytes[i];
}
return string(_newValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment