add: str_replace
This commit is contained in:
parent
6d2b0a74c4
commit
698e18ecb4
@ -10,3 +10,4 @@ void str_shift(char *str, int shift);
|
|||||||
int str_contain_only(const char *str, const char *charset);
|
int str_contain_only(const char *str, const char *charset);
|
||||||
char* str_merger(size_t arg_len, ...);
|
char* str_merger(size_t arg_len, ...);
|
||||||
char* str_join(const char* s1, const char* s2);
|
char* str_join(const char* s1, const char* s2);
|
||||||
|
char* str_replace(const char *str, const char *fill, size_t start, size_t stop);
|
||||||
|
19
src/str/str_replace.c
Normal file
19
src/str/str_replace.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "./str.h"
|
||||||
|
|
||||||
|
char *str_replace(const char *str, const char *fill, size_t start, size_t stop)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
size_t sum;
|
||||||
|
|
||||||
|
out = malloc((strlen(str) + strlen(fill) -\
|
||||||
|
(stop - start) + 1 * sizeof(char)));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user