![]() |
![]()
| ![]() |
![]()
NAMExt_strsplit() - Split a string into tokens LIBRARY#include <xtend/string.h> -lxtend SYNOPSISint xt_strsplit(char *string, char ***array, const char *sep) ARGUMENTSstring String to be parsed for tokens array Pointer array to be filled with tokens sep Character string listing all recognized separators DESCRIPTIONxt_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 immediately processed and forgotten, use a loop with strsep(). Introducing arrays into a program unnecessarily should avoided as a habit to maximize 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 VALUESThe number of tokens into which string is separated, or 0 if a memory allocation or other failure occurred. EXAMPLESchar *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) SEE ALSOstrsep(3)
|