@@ -155,7 +155,7 @@ defmodule String do
155
155
@spec split ( t ) :: [ t ]
156
156
defdelegate split ( binary ) , to: String.Unicode
157
157
158
- @doc """
158
+ @doc % S """
159
159
Divides a string into substrings based on a pattern,
160
160
returning a list of these substrings. The pattern can
161
161
be a string, a list of strings or a regular expression.
@@ -168,30 +168,33 @@ defmodule String do
168
168
169
169
## Examples
170
170
171
+ Splitting with a string pattern:
172
+
171
173
iex> String.split("a,b,c", ",")
172
174
["a", "b", "c"]
173
175
iex> String.split("a,b,c", ",", global: false)
174
176
["a", "b,c"]
175
177
iex> String.split(" a b c ", " ", trim: true)
176
178
["a", "b", "c"]
177
179
180
+ A list of patterns:
181
+
178
182
iex> String.split("1,2 3,4", [" ", ","])
179
183
["1", "2", "3", "4"]
180
184
185
+ A regular expression:
186
+
181
187
iex> String.split("a,b,c", %r{,})
182
188
["a", "b", "c"]
183
189
iex> String.split("a,b,c", %r{,}, global: false)
184
190
["a", "b,c"]
185
- iex> String.split("a,b", %r{\\ .})
186
- ["a,b"]
191
+ iex> String.split(" a b c ", %r{\s }, trim: true)
192
+ ["a", "b", "c"]
193
+
194
+ Splitting on empty patterns returns codepoints:
187
195
188
- iex> String.split("abc", %r{c})
189
- ["ab", ""]
190
196
iex> String.split("abc", %r{})
191
197
["a", "b", "c", ""]
192
- iex> String.split("abc", %r{}, trim: true)
193
- ["a", "b", "c"]
194
-
195
198
iex> String.split("abc", "")
196
199
["a", "b", "c", ""]
197
200
iex> String.split("abc", "", trim: true)
@@ -206,7 +209,7 @@ defmodule String do
206
209
207
210
def split ( "" , _pattern , _options ) , do: [ "" ]
208
211
209
- def split ( binary , "" , options ) , do: split ( binary , % r "" , options )
212
+ def split ( binary , "" , options ) , do: split ( binary , % r "" u , options )
210
213
211
214
def split ( binary , pattern , options ) when is_regex ( pattern ) do
212
215
Regex . split ( pattern , binary , options )
0 commit comments