comparison lispref/strings.texi @ 51149:337c29aec7ce

(Creating Strings): Update split-string specification and examples.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 22 May 2003 21:05:25 +0000
parents 23a1cea22d13
children 1cb98e67d9b2
comparison
equal deleted inserted replaced
51148:f59aeee43725 51149:337c29aec7ce
257 description of @code{mapconcat} in @ref{Mapping Functions}, 257 description of @code{mapconcat} in @ref{Mapping Functions},
258 @code{vconcat} in @ref{Vectors}, and @code{append} in @ref{Building 258 @code{vconcat} in @ref{Vectors}, and @code{append} in @ref{Building
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:
278
279 @example
280 (split-string " two words ")
281 @result{} ("two" "words")
282 @end example
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" "")
291 @end example
292
293 More examples:
271 294
272 @example 295 @example
273 (split-string "Soup is good food" "o") 296 (split-string "Soup is good food" "o")
274 @result{} ("S" "up is g" "" "d f" "" "d") 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")
275 (split-string "Soup is good food" "o+") 300 (split-string "Soup is good food" "o+")
276 @result{} ("S" "up is g" "d f" "d") 301 @result{} ("S" "up is g" "d f" "d")
277 @end example
278
279 When there is a match adjacent to the beginning or end of the string,
280 this does not cause a null string to appear at the beginning or end
281 of the list:
282
283 @example
284 (split-string "out to moo" "o+")
285 @result{} ("ut t" " m")
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:
289 305
290 @example 306 @example