Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. library Strings {
  4. function concat(string _base, string _value) internal returns(string) {
  5. bytes memory _baseBytes = bytes(_base);
  6. bytes memory _valueBytes = bytes(_value);
  7.  
  8. string memory _tmpValue = new string(_valueBytes.length + _valueBytes.length);
  9. bytes memory _newValue = bytes(_tmpValue);
  10.  
  11. uint i;
  12. uint j;
  13.  
  14. for(i=0; i<_baseBytes.length; i++){
  15. _newValue[j++] = _baseBytes[i];
  16. }
  17.  
  18. for(i=0; i<_valueBytes.length; i++){
  19. _newValue[j++] = _valueBytes[i];
  20. }
  21.  
  22. return string(_newValue);
  23. }
  24.  
  25. function strpos(string _base, string _value) internal returns (int) {
  26. bytes memory _baseBytes = bytes(_base);
  27. bytes memory _valueBytes = bytes(_value);
  28.  
  29. assert(_valueBytes.length == 1);
  30.  
  31. for(uint i=0; i<_baseBytes.length; i++){
  32. if(_baseBytes[i] == _valueBytes[0]){
  33. return int(i);
  34. }
  35. }
  36. return -1;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement