-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
30 lines (27 loc) · 1.19 KB
/
ft_strtrim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 17:58:31 by mdenys #+# #+# */
/* Updated: 2020/11/03 11:18:41 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *new;
int len;
len = 0;
if (!s1 || !set)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
len = ft_strlen((char*)s1);
while (len && ft_strchr(set, s1[len]))
len--;
new = ft_substr((char *)(s1), 0, len + 1);
return (new);
}