Created
July 31, 2018 20:57
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract Concatenation { | |
struct Element{ | |
string first; | |
string second; | |
string separator; | |
bytes concatenatedValue; | |
uint concatenatedValueIndex; | |
} | |
Element element; | |
function concatenate(string _first, string _second, string _separator) public payable returns (string){ | |
element = Element(_first, _second, _separator, "0X12", 0); | |
createConcatenatedValue(element); | |
executeConcatenation(); | |
return getConcatanatedValue(); | |
} | |
function createConcatenatedValue(Element _element) private{ | |
string memory value = new string(bytes(_element.first).length + bytes(_element.second).length + bytes(_element.separator).length); | |
element.concatenatedValue = bytes(value); | |
} | |
function add(string _value) private { | |
bytes memory value = bytes(_value); | |
for(uint index = 0; index < value.length; index++){ | |
element.concatenatedValue[element.concatenatedValueIndex++] = value[index]; | |
} | |
} | |
function executeConcatenation() private { | |
add(element.first); | |
add(element.separator); | |
add(element.second); | |
} | |
function getConcatanatedValue() private view returns(string){ | |
return string(element.concatenatedValue); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract Concatenation { | |
function concatenate(string _first, string _second, string _separator) public view returns (string) {} | |
} | |
contract StringUtil { | |
address concatenationContractAddress = 0x0dcd2f752394c41875e259e00bb44fd505297caf; | |
Concatenation concatenation = Concatenation(concatenationContractAddress); | |
function concatenate(string _first, string _second, string _separator) public view returns (string){ | |
return concatenation.concatenate(_first, _second, _separator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment