0

Any idea for the simplest way to add "degrees" variable into the string like below? Looking for getString to return "today is 40 degrees outside".

 pragma solidity ^0.5.3;

        uint public degrees= 40;

        function getString() public view returns(string memory){
                string memory a = "today is ";
                string memory b = degrees;
                string memory c = "degrees outside";
                string memory sentence = string(abi.encodePacked(a, b, c));
                return sentence;
        }
2

oraclize helped

 pragma solidity ^0.5.3;

        uint public degrees= 40;

        function getString() public view returns(string memory){
                string memory a = "today is ";
                string memory b = uint2str(degrees);
                string memory c = "degrees outside";
                string memory sentence = string(abi.encodePacked(a, b, c));
                return sentence;
        }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.