Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
xt_strsplit(3)		   Library Functions Manual		xt_strsplit(3)

NAME
       xt_strsplit() - Split a string into tokens

LIBRARY
       #include	<xtend/string.h>
       -lxtend

SYNOPSIS
       int     xt_strsplit(char	*string, char ***array,	const char *sep)

ARGUMENTS
       string  String to be parsed for tokens
       array   Pointer array to	be filled with tokens
       sep     Character string	listing	all recognized separators

DESCRIPTION
       xt_strsplit() splits a string into tokens separated by any character in
       the  string argument sep.  The function interface is similar to split()
       in awk, except that sep is a simple list	of characters  rather  than  a
       regular expression.

       The  array  argument  should  be	 the  address  of  a char ** variable.
       xt_strsplit() allocates memory for the pointers as needed  and  assigns
       one token to each pointer.

       xt_strsplit() should only be used when an array of strings representing
       the  tokens is actually needed.	In cases where each token can be imme-
       diately processed and forgotten,	use a loop with	strsep().  Introducing
       arrays into a program unnecessarily should avoided as a habit to	 maxi-
       mize speed and minimize memory use.

       Caution:	 xt_strsplit()	is  destructive: It replaces the separators in
       string with null	bytes.	To preserve the	original string, duplicate  it
       with strdup() first and pass the	copy to	xt_strsplit().

RETURN VALUES
       The  number  of tokens into which string	is separated, or 0 if a	memory
       allocation or other failure occurred.

EXAMPLES
       char    *string = "1,2,3,4,5", *copy, **array;
       size_t  c, tokens;

       copy = strdup(string);
       tokens =	xt_strsplit(copy, &array, ",");
       for (int	c = 0; c < tokens; ++c)
	   puts(array[c]);

SEE ALSO
       strsep(3)

								xt_strsplit(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=xt_strsplit&sektion=3&manpath=FreeBSD+Ports+14.3.quarterly>

home | help