Created
January 12, 2018 15:33
-
-
Save onokatio/473077dfa72dea81610eb26971e20d39 to your computer and use it in GitHub Desktop.
Solidityで文字列連結 ref: https://qiita.com/onokatio/items/4d74229bd6015379e379
This file contains hidden or 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
| string memory str1 = "abc"; | |
| string memory str2 = "def"; | |
| bytes memory strbyte1 = bytes(str1); | |
| bytes memory strbyte2 = bytes(str2); |
This file contains hidden or 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
| bytes memory str = new bytes(strbyte1.length + strbyte2.length); |
This file contains hidden or 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
| 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++; | |
| } |
This file contains hidden or 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
| return string(str); |
This file contains hidden or 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.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