开发者社区 问答 正文

编写一个MyString合约,传入一个字符串,字符左右拼接<>

编写一个MyString合约,传入一个字符串,字符左右拼接<>

展开
收起
北藏有名 2020-02-06 16:38:00 1072 分享 版权
1 条回答
写回答
取消 提交回答
  • 有点尴尬唉 你要寻找的东西已经被吃掉啦!

    MyString -------> pragma solidity>=0.4.23; contract MyString{ function formatString(string target) returns(string){

        bytes targetBytes=bytes(target)
        //定义一个定长返回的变量
        string str=string(targetBytes.length*3)
        bytes resultBytes=bytes(str)
        uint index=0;
        for(uint i=0;i<=targetBytes.length;i++){
            resultBytes[index++]="<"
            resultBytes[index++]=targetBytes[i]
            resultBytes[index++]=">"
        }
        return string(resultBytes)
    }
    

    }

    2020-02-06 16:38:42
    赞同 展开评论
问答地址: