Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
libft/ft_strtrim.c
2023-11-11 01:28:12 +01:00

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);
}