How to use string in Solidity programming language ?

How to use string in Solidity programming language ?


 pragma solidity ^0.5.0;


contract SolidityTest {   

   constructor() public{       

   }

   function getResult() public view returns(string memory){

      uint a = 1; 

      uint b = 2;

      uint result = a + b;

      return integerToString(result); 

   }

   function integerToString(uint _i) internal pure 

      returns (string memory) {

      

      if (_i == 0) {

         return "0";

      }

      uint j = _i;

      uint len;

      

      while (j != 0) {

         len++;

         j /= 10;

      }

      bytes memory bstr = new bytes(len);

      uint k = len - 1;

      

      while (_i != 0) {

         bstr[k--] = byte(uint8(48 + _i % 10));

         _i /= 10;

      }

      return string(bstr);

   }

}

Comments

Last 7 Days

How to use sandbox attribute value ( allow-popups ) with < iframe > tag in HTML ? with example

How do you add color to a < table > in HTML?

table background-color css

what is solidity programming language ?

How to add Amazon website inside iframe?

How to Create a table in html with 2 rows and 3 columns (Source code )

How to use referrerpolicy Attribute value ( no-referrer-when-downgrade ) with < iframe > tag in HTML ? with example

How to use loop attribute with < video > tag in HTML for YouTube ? with example

All 35 reserved keywords in Solidity programming language