Skip to content

Commit 4a1f0b8

Browse files
committed
Document string.split's new optional limit parameter
1 parent 4ac6738 commit 4a1f0b8

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

docs/Runtime Environment/String.md

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,20 @@ Splits a string by a separator.
2323
#### Parameters
2424
1. The string to split.
2525
2. The separator to split a string by. This can be any string.
26+
3. An optional limit for the returned table size.
2627
#### Returns
2728
A table.
28-
```pluto title="Splitting a string by a single character."
29+
```pluto title="Splitting a string by a single character"
2930
local s = "hello world, how is everyone doing?"
30-
local r = string.split(s, " ")
31-
--[[
32-
The value of 'r':
33-
{
34-
"hello",
35-
"world,",
36-
"how",
37-
"is",
38-
"everyone",
39-
"doing?"
40-
}
41-
--]]
31+
string.split(s, " ") -- { "hello", "world,", "how", "is", "everyone", "doing?" }
4232
```
43-
```pluto title="Splitting a string by a substring."
44-
local s = "helloHALLOWORLDworld,HALLOWORLDhowHALLOWORLDisHALLOWORLDeveryoneHALLOWORLDdoing?"
45-
local r = string.split(s, "HALLOWORLD")
46-
--[[
47-
The value of 'r':
48-
{
49-
"hello",
50-
"world,",
51-
"how",
52-
"is",
53-
"everyone",
54-
"doing?"
55-
}
56-
--]]
33+
```pluto title="Splitting a string by a substring"
34+
local s = "helloFOOworld,FOOhowFOOisFOOeveryoneFOOdoing?"
35+
string.split(s, "FOO") -- { "hello", "world,", "how", "is", "everyone", "doing?" }
36+
```
37+
```pluto title="Splitting a string by a single character with a limit"
38+
local s = "hello world, how is everyone doing?"
39+
string.split(s, " ", 3) -- { "hello", "world,", "how is everyone doing?" }
5740
```
5841
---
5942
### `string.rfind`

0 commit comments

Comments
 (0)