32 lines
1.2 KiB
C
32 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strtrim.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/11/11 00:37:37 by adjoly #+# #+# */
|
|
/* Updated: 2023/11/11 01:09:36 by adjoly ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strtrim(char const *s1, char const *set)
|
|
{
|
|
int i;
|
|
int j;
|
|
char *result;
|
|
|
|
i = 0;
|
|
if (s1 == NULL || set == NULL)
|
|
return (NULL);
|
|
j = ft_strlen(s1);
|
|
while (ft_strchr(set, s1[i]) != 0)
|
|
i++;
|
|
while (ft_strrchr(set, s1[j]) != 0)
|
|
j--;
|
|
result = ft_substr(s1, i, (j - i) + 1);
|
|
return (result);
|
|
}
|