split() : Split String into Array
On this page
Summary
Split a string into an array of substrings based on a separator.
Signature
split(str, separator)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
str |
String | Yes | The string to split |
separator |
String | Yes | The separator to split on |
Returns
Type: Array of strings
An array containing the split substrings.
Examples
Split CSV
Data:
doc.Params["model"] = new {
tags = "javascript, html, css, react"
};
Output:
<ul>
<li>javascript</li>
<li>html</li>
<li>css</li>
<li>react</li>
</ul>
Split Full Name
Data:
doc.Params["model"] = new {
fullName = "John Doe"
};
Output:
<p>First Name: John</p>
<p>Last Name: Doe</p>
Split Path
Data:
doc.Params["model"] = new {
path = "home/documents/reports/2024"
};
Output:
<ul class="breadcrumb">
<li>home</li>
<li>documents</li>
<li>reports</li>
<li>2024</li>
</ul>
Count Occurrences
Data:
doc.Params["model"] = new {
sentence = "This is a sample sentence"
};
Output:
<p>Words: 5</p>
Notes
- Returns array of substrings
- Empty strings included if separator appears consecutively
- If separator not found, returns array with single element (original string)
- Case-sensitive matching
- Use with `` to iterate results
- Use with
trim()to clean up whitespace - Opposite of
join()function