想知道更多区块链技术知识,请百度【链客区块链技术问答社区】链客,有问必答!string是数组,solidity不支持动态扩容,只能写个for循环一个个加,此处采用的做法是转成bytes
function stringAdd(string a, string b) returns(string){
bytes memory _a = bytes(a);bytes memory _b = bytes(b);bytes memory res = new bytes(_a.length + _b.length);for(uint i = 0;i < _a.length;i++) res[i] = _a[i];for(uint j = 0;j < _b.length;j++) res[_a.length+j] = _b[j]; return string(res);
}