Created
April 12, 2019 12:10
-
-
Save Chanutg/5bc9facbc26f01303be1b6b0facd8e96 to your computer and use it in GitHub Desktop.
HelloWorld
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.5.0; | |
contract HelloWorld { | |
string public sentence; | |
string public userName; | |
constructor() public { | |
sentence = "HelloWorld !"; | |
userName = "Guillaume"; | |
} | |
function saySomething() public view returns(string memory){ | |
return (concat(sentence, userName)); | |
} | |
function changeSentence(string memory newSentence) public { | |
sentence = newSentence; | |
} | |
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