Description
The segment function splits the string string into individual, separator-separated segments and returns the segment at the specified index.
Syntax
segment(string, separator[, index])
Arguments
| Argument | Description |
|---|---|
string |
The string to be split into segments. |
separator |
The delimiter that separates the segments within the string. |
index (optional) |
Specifies the position of the segment to be returned. Counting starts at 0, where index = 0 returns the first segment. |
Return Types
The function returns the segment at the specified index as text.
Examples
| Description | Formula | Result |
|---|---|---|
| First segment of the string |
segment("I love unicorns.", " ", 0)
|
"I" |
| Second segment of the string |
segment("I love unicorns.", " ", 1)
|
"love" |
| Third segment of the string |
segment("I love unicorns.", " ", 2)
|
"unicorns." |
Notes
- Counting starts at 0, not at 1.
- If the
indexis outside the available segments, the function returns an empty value.
Comments
0 comments
Please sign in to leave a comment.