diff options
| author | Juanma Barranquero | 2003-05-22 21:05:25 +0000 |
|---|---|---|
| committer | Juanma Barranquero | 2003-05-22 21:05:25 +0000 |
| commit | 3aeea9e980bdbda4b837566a964f3eb7354d1bf2 (patch) | |
| tree | a87ddf81574e1cf02be4c32ee8f094c7f1650be7 | |
| parent | 6a646626960dda937b81febd43140946a1f64111 (diff) | |
| download | emacs-3aeea9e980bdbda4b837566a964f3eb7354d1bf2.tar.gz emacs-3aeea9e980bdbda4b837566a964f3eb7354d1bf2.zip | |
(Creating Strings): Update split-string specification and examples.
| -rw-r--r-- | lispref/strings.texi | 42 |
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}, | |||
| 259 | Lists}. | 259 | Lists}. |
| 260 | @end defun | 260 | @end defun |
| 261 | 261 | ||
| 262 | @defun split-string string separators | 262 | @defun split-string string separators omit-nulls |
| 263 | This function splits @var{string} into substrings at matches for the regular | 263 | This function splits @var{string} into substrings at matches for the regular |
| 264 | expression @var{separators}. Each match for @var{separators} defines a | 264 | expression @var{separators}. Each match for @var{separators} defines a |
| 265 | splitting point; the substrings between the splitting points are made | 265 | splitting point; the substrings between the splitting points are made |
| 266 | into a list, which is the value returned by @code{split-string}. | 266 | into 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 | ||
| 268 | result list. Otherwise, null strings are left in the result. | ||
| 267 | If @var{separators} is @code{nil} (or omitted), | 269 | If @var{separators} is @code{nil} (or omitted), |
| 268 | the default is @code{"[ \f\t\n\r\v]+"}. | 270 | the default is the value of @code{split-string-default-separators}. |
| 269 | 271 | ||
| 270 | For example, | 272 | @defvar split-string-default-separators |
| 273 | The default value of @var{separators} for @code{split-string}, initially | ||
| 274 | @samp{"[ \f\t\n\r\v]+"}. | ||
| 275 | |||
| 276 | As a special case, when @var{separators} is @code{nil} (or omitted), | ||
| 277 | null 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 | |
| 284 | The result is not @samp{("" "two" "words" "")}, which would rarely be | ||
| 285 | useful. 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 | ||
| 279 | When there is a match adjacent to the beginning or end of the string, | 293 | More examples: |
| 280 | this does not cause a null string to appear at the beginning or end | ||
| 281 | of 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 | ||
| 288 | Empty matches do count, when not adjacent to another match: | 304 | Empty matches do count, when not adjacent to another match: |