Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.24;
- library Strings {
- function concat(string _base, string _value) internal returns(string) {
- bytes memory _baseBytes = bytes(_base);
- bytes memory _valueBytes = bytes(_value);
- string memory _tmpValue = new string(_valueBytes.length + _valueBytes.length);
- bytes memory _newValue = bytes(_tmpValue);
- uint i;
- uint j;
- for(i=0; i<_baseBytes.length; i++){
- _newValue[j++] = _baseBytes[i];
- }
- for(i=0; i<_valueBytes.length; i++){
- _newValue[j++] = _valueBytes[i];
- }
- return string(_newValue);
- }
- function strpos(string _base, string _value) internal returns (int) {
- bytes memory _baseBytes = bytes(_base);
- bytes memory _valueBytes = bytes(_value);
- assert(_valueBytes.length == 1);
- for(uint i=0; i<_baseBytes.length; i++){
- if(_baseBytes[i] == _valueBytes[0]){
- return int(i);
- }
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement