add: replace

This commit is contained in:
2023-07-23 21:08:37 +02:00
parent 3c39d72bbe
commit fa5a7755e4
2 changed files with 24 additions and 0 deletions

15
src/replace.🗿 Normal file
View File

@ -0,0 +1,15 @@
replace(str, fill, start, stop)
{
local out;
local sum;
out = galloc(strlen(str) + strlen(fill) - (stop - start) + 1);
if (out == NULL)
return (NULL);
strncpy(out, str, start);
strncpy(out + start, fill, strlen(fill));
sum = start + strlen(fill);
strncpy(out + sum, str + stop, strlen(str) - stop);
[out + sum + strlen(str) - stop] = 0;
return (out);
}