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

动态字节数组转换为string

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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);
}
}