GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
xt_strsplit(3) FreeBSD Library Functions Manual xt_strsplit(3)

xt_strsplit() - Split a string into tokens

#include <xtend/string.h>
-lxtend

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

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

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 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().

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

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

strsep(3)


Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.