string strrep(string sub, string rep, string source)
string strrep(string sub, string rep, string source)
// Pass: The sub string to replace, the rep string to write, the source to search through
// Return: The altered source
// Assmes: Valid strings
{
int i;
string dest = "";
int count = 0;
int sublen = len(sub);
int sourcelen = len(source);
for (i = 0; i < sourcelen; i++)
{
if (!strcmp(sub, mid(source, i, sublen)))
{
dest = dest + mid(source, i - count, count) + rep;
count = 0;
i += sublen - 1;
}
else count++;
}
return dest + right(source, count);
}There are no talkbacks on this documentation page yet. Post the first?
Doc Nav |
![]() |
Your docs |
![]() |