### Function

# GLib strsplit

#### Declaration

    gchar**
    g_strsplit (
      const gchar* string,
      const gchar* delimiter,
      gint max_tokens
    )

#### Description

Splits a string into a maximum of `max_tokens` pieces, using the given `delimiter`. If `max_tokens` is reached, the remainder of `string` is appended to the last token.

As an example, the result of `g_strsplit (":a:bc::d:", ":", -1)` is an array containing the six strings “”, “a”, “bc”, “”, “d” and “”.

As a special case, the result of splitting the empty string “” is an empty array, not an array containing a single string. The reason for this special case is that being able to represent an empty array is typically more useful than consistent handling of empty elements. If you do need to represent empty elements, you’ll need to check for the empty string before calling `g_strsplit()`.

#### Parameters

`string`

  Type: `const gchar*`

  A string to split.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`delimiter`

  Type: `const gchar*`

  A string which specifies the places at which to split the string. The delimiter is not included in any of the resulting strings, unless `max_tokens` is reached.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`max_tokens`

  Type: `gint`

  The maximum number of pieces to split `string` into If this is less than 1, the string is split completely.

#### Return value

Type: An array of `utf8`

A newly-allocated array of strings, freed with `g_strfreev()`.

The array is `NULL`-terminated.
The caller of the function takes ownership of the data, and is responsible for freeing it.
Each element is a NUL terminated UTF-8 string.