aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2003-05-22 21:05:25 +0000
committerJuanma Barranquero2003-05-22 21:05:25 +0000
commit3aeea9e980bdbda4b837566a964f3eb7354d1bf2 (patch)
treea87ddf81574e1cf02be4c32ee8f094c7f1650be7
parent6a646626960dda937b81febd43140946a1f64111 (diff)
downloademacs-3aeea9e980bdbda4b837566a964f3eb7354d1bf2.tar.gz
emacs-3aeea9e980bdbda4b837566a964f3eb7354d1bf2.zip
(Creating Strings): Update split-string specification and examples.
-rw-r--r--lispref/strings.texi42
1 files changed, 29 insertions, 13 deletions
diff --git a/lispref/strings.texi b/lispref/strings.texi
index 0870e0b5369..24dbd4f0f1e 100644
--- a/lispref/strings.texi
+++ b/lispref/strings.texi
@@ -259,30 +259,46 @@ description of @code{mapconcat} in @ref{Mapping Functions},
259Lists}. 259Lists}.
260@end defun 260@end defun
261 261
262@defun split-string string separators 262@defun split-string string separators omit-nulls
263This function splits @var{string} into substrings at matches for the regular 263This function splits @var{string} into substrings at matches for the regular
264expression @var{separators}. Each match for @var{separators} defines a 264expression @var{separators}. Each match for @var{separators} defines a
265splitting point; the substrings between the splitting points are made 265splitting point; the substrings between the splitting points are made
266into a list, which is the value returned by @code{split-string}. 266into a list, which is the value returned by @code{split-string}. If
267@var{omit-nulls} is @code{t}, null strings will be removed from the
268result list. Otherwise, null strings are left in the result.
267If @var{separators} is @code{nil} (or omitted), 269If @var{separators} is @code{nil} (or omitted),
268the default is @code{"[ \f\t\n\r\v]+"}. 270the default is the value of @code{split-string-default-separators}.
269 271
270For example, 272@defvar split-string-default-separators
273The default value of @var{separators} for @code{split-string}, initially
274@samp{"[ \f\t\n\r\v]+"}.
275
276As a special case, when @var{separators} is @code{nil} (or omitted),
277null strings are always omitted from the result. Thus:
271 278
272@example 279@example
273(split-string "Soup is good food" "o") 280(split-string " two words ")
274@result{} ("S" "up is g" "" "d f" "" "d") 281@result{} ("two" "words")
275(split-string "Soup is good food" "o+") 282@end example
276@result{} ("S" "up is g" "d f" "d") 283
284The result is not @samp{("" "two" "words" "")}, which would rarely be
285useful. If you need such a result, use an explict value for
286@var{separators}:
287
288@example
289(split-string " two words " split-string-default-separators)
290@result{} ("" "two" "words" "")
277@end example 291@end example
278 292
279When there is a match adjacent to the beginning or end of the string, 293More examples:
280this does not cause a null string to appear at the beginning or end
281of the list:
282 294
283@example 295@example
284(split-string "out to moo" "o+") 296(split-string "Soup is good food" "o")
285@result{} ("ut t" " m") 297@result{} ("S" "up is g" "" "d f" "" "d")
298(split-string "Soup is good food" "o" t)
299@result{} ("S" "up is g" "d f" "d")
300(split-string "Soup is good food" "o+")
301@result{} ("S" "up is g" "d f" "d")
286@end example 302@end example
287 303
288Empty matches do count, when not adjacent to another match: 304Empty matches do count, when not adjacent to another match: