Skip to content

Instantly share code, notes, and snippets.

@onokatio
Created January 12, 2018 15:33
Show Gist options
  • Save onokatio/473077dfa72dea81610eb26971e20d39 to your computer and use it in GitHub Desktop.
Save onokatio/473077dfa72dea81610eb26971e20d39 to your computer and use it in GitHub Desktop.
string memory str1 = "abc";
string memory str2 = "def";
bytes memory strbyte1 = bytes(str1);
bytes memory strbyte2 = bytes(str2);
bytes memory str = new bytes(strbyte1.length + strbyte2.length);
uint8 point = 0;
for(uint8 j = 0; j < strbyte1.length;j++){
str[point] = strbyte1[j];
point++;
}
for(uint8 k = 0; k < strbyte2.length;k++){
str[point] = strbyte2[k];
point++;
}
return string(str);
pragma solidity ^0.4.19;
contract MyStringTest {
function strConnect() public constant returns(string){
string memory str1 = "abc";
string memory str2 = "def";
bytes memory strbyte1 = bytes(str1);
bytes memory strbyte2 = bytes(str2);
bytes memory str = new bytes(strbyte1.length + strbyte2.length);
uint8 point = 0;
for(uint8 j = 0; j < strbyte1.length;j++){
str[point] = strbyte1[j];
point++;
}
for(uint8 k = 0; k < strbyte2.length;k++){
str[point] = strbyte2[k];
point++;
}
return string(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment