三、Solidity中的string运用

pragma solidity ^0.5.1;

contract HelloWord{
   string  public name= "zhuxing";
    
    
    function getName() view public returns( string memory){
        return name;
    }
    
    function setName(string memory _name ) public {
        name=_name;
    }
    
    function getLength() public view returns(uint){
        return bytes(name).length;
    }
    
    function changName() public{
        bytes(name)[0]='Z';
    }
    
    function getBytes() public view returns(bytes memory){
        return bytes(name);
    }
}

你可能感兴趣的:(三、Solidity中的string运用)