Skip to content

Instantly share code, notes, and snippets.

@maymax777
Last active February 11, 2022 11:44
Show Gist options
  • Save maymax777/1270c56a47c7fe59813610ee9811f19c to your computer and use it in GitHub Desktop.
Save maymax777/1270c56a47c7fe59813610ee9811f19c to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.13;
contract Repeater {
function multiply(uint8 repeat, string pattern) returns (string) {
bytes memory bpattern = bytes(pattern);
uint resultLength = repeat * bpattern.length;
string memory result = new string(resultLength);
bytes memory bresult = bytes(result);
for (uint i = 0; i < resultLength; i++) {
bresult[i] = bpattern[i % bpattern.length];
}
return string(bresult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment