【初心者でもできる!】Solidityの文字列結合とRemix-Solidityの使い方
「Solidityで文字列結合ができない!?」
と、悩まれる方多いのではないでしょうか?
ライブラリを使用することで、初心者でも簡単に文字列結合をすることができます。
日本語の記事が無かったので書いてみようと思いました。
英語ですが、下記のページに詳細が書いてあります。
https://github.com/Arachnid/solidity-stringutils
では早速見てみましょう。
3つの文字列を結合するサンプルです。
import "github.com/Arachnid/solidity-stringutils/strings.sol";
contract Solidity {
using strings for *;
string public s;
string public ss;
function foo(string s1, string s2, string s3) {
s = s1.toSlice().concat(s2.toSlice());
ss = s.toSlice().concat(s3.toSlice());
}
}
このコードを、統合開発環境のRemix-Solidityで試してみたいと思います。
ついでなので、丁寧にRemix-Solidityの使い方も画像と一緒に説明していきます。
Remix−Solidity
上記のような画面になったと思います。
そしたら、右側のEnvironmentをJavaScript VMに変えます。
foo関数に結合したい文字を3つ入れます。
今回、"Hello ", "World ", "Solidity"
といれてみます。
結合できました!
参照元
https://github.com/Arachnid/solidity-stringutils
https://stackoverflow.com/questions/32157648/string-concatenation-in-solidity
Author And Source
この問題について(【初心者でもできる!】Solidityの文字列結合とRemix-Solidityの使い方), 我々は、より多くの情報をここで見つけました https://qiita.com/bell22/items/f6f3f17f28c1251d6725著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .