Solidity字符串拼接实现oraclize动态查询
solidity本身没有字符串拼接功能,但是如果你恰巧要用oraclize api,那么可以使用oraclize api中的字符串拼接方法(strConcat)。之所以oraclize api里会有strConcat方法,我想是因为方便用户实现动态查询。
//auther: shiming liu pragma solidity ^0.4.21; import "github.com/oraclize/ethereum-api/oraclizeAPI.sol"; contract strConcatContract is usingOraclize{ string urlPrefix = "https://api.iextrading.com/1.0/stock/"; string stock_name = "aapl"; string underline = "_"; uint date = 3100; string PRICE = "/price"; string public url = strConcat(urlPrefix,stock_name,underline,uint2str(date),PRICE); // "https://api.iextrading.com/1.0/stock/aapl_3100/price" }
1.001^365=1.44......life is a project
原创文章,转载请注明出处!