Strings.sol 859 B

1234567891011121314151617181920212223242526272829303132
  1. pragma solidity ^0.5.0;
  2. /**
  3. * @title Strings
  4. * @dev String operations.
  5. */
  6. library Strings {
  7. /**
  8. * @dev Converts a `uint256` to a `string`.
  9. * via OraclizeAPI - MIT licence
  10. * https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
  11. */
  12. function fromUint256(uint256 value) internal pure returns (string memory) {
  13. if (value == 0) {
  14. return "0";
  15. }
  16. uint256 temp = value;
  17. uint256 digits;
  18. while (temp != 0) {
  19. digits++;
  20. temp /= 10;
  21. }
  22. bytes memory buffer = new bytes(digits);
  23. uint256 index = digits - 1;
  24. temp = value;
  25. while (temp != 0) {
  26. buffer[index--] = byte(uint8(48 + temp % 10));
  27. temp /= 10;
  28. }
  29. return string(buffer);
  30. }
  31. }