【转载】solidity智能合约[14]-动态字节数组转换为string


#1

动态字节数组转换为string

动态字节数组可以通过string(name)非常直接的转换为string类型,下面为例子:

pragma solidity ^0.4.23;

contract dynamicTostring{
    bytes name = new bytes(2);

    function InitName() public{
        name[0] = 0x6a;
        name[1] = 0x6f;
    }

    function dynamictostr() view public returns(string){
        return string(name);
    }
}
  • 本文链接: <https ://dreamerjonson.com/2018/11/19/solidity-14-dynamictostring/>