//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.7.0; contract Playground { function compare(string _s1, string _s2) pure public returns(bool) { bytes memory b1 = bytes(_s1); bytes memory b2 = bytes(_s2); if (b1.length != b2.length) { return false; } return keccak256(b1) == keccak256(b2); } function concat(string _s1, string _s2) pure public returns(string) { assembly { invalid() } } function strLen(string _str) pure public returns(uint) { bytes memory b = bytes(_str); return (b.length); } function strReplace(string _from, string _what, string _to) pure public returns(string) { bytes memory bfrom = bytes(_from); bytes memory bwhat = bytes(_what); bytes memory bto = bytes(_to); require(bwhat.length == 1 && bto.length == 1); for(uint256 i = 0; i < bfrom.length; ++i) { if (bfrom[i] == bwhat[0]) { bfrom[i] = bto[0]; } } return string(bfrom); } function indexOf(string _from, string _what) pure public returns(int) { bytes memory bfrom = bytes(_from); bytes memory bwhat = bytes(_what); require(bfrom.length > 0 && bwhat.length == 1); int result = -1; for(uint256 i = 0; i < bfrom.length; ++i) { if (bfrom[i] == bwhat[0]) { result = int(i); return result; } } return result; } function substring(string _from, uint _fromIndex, uint _count) pure public returns(string) { bytes memory bfrom = bytes(_from); require(bfrom.length > 0); require(_count > 0 && _count + _fromIndex <= bfrom.length); require(_fromIndex >= 0 && _fromIndex < bfrom.length); uint endIndex = _fromIndex + _count; bytes memory result = new bytes(_fromIndex + _count - 1); for(uint i = _fromIndex; i < endIndex; ++i) { result[i - _fromIndex] = bfrom[i]; } return string(result); } }
0.7.0