-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix String.split/3 example in guide and add note in docs #14223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
dd46ead
6f7c9ca
b0d76be
126f450
16724b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ iex> String.split("1 2 3", " ") | |
["1", "", "2", "", "3"] | ||
``` | ||
|
||
As you can see, there are now empty strings in our results. Luckily, the `String.split/3` function allows the `trim` option to be set to true: | ||
As you can see, there are now empty strings in our results. Luckily, the `String.split/3` function allows the `trim` option to be set to true to remove empty entries from the result: | ||
|
||
```elixir | ||
iex> String.split("1 2 3", " ", [trim: true]) | ||
|
@@ -33,14 +33,14 @@ We can also use options to limit the splitting algorithm to a maximum number of | |
|
||
```elixir | ||
iex> String.split("1 2 3", " ", [trim: true, parts: 2]) | ||
|
||
["1", "2 3"] | ||
["1", " 2 3"] | ||
``` | ||
|
||
`[trim: true]` and `[trim: true, parts: 2]` are keyword lists. When a keyword list is the last argument of a function, we can skip the brackets and write: | ||
|
||
```elixir | ||
iex> String.split("1 2 3", " ", trim: true, parts: 2) | ||
["1", "2 3"] | ||
["1", " 2 3"] | ||
``` | ||
|
||
As shown in the example above, keyword lists are mostly used as optional arguments to functions. | ||
|
Uh oh!
There was an error while loading. Please reload this page.