comparison man/lispref/searching.texi @ 1495:c3cf7db99b98

[xemacs-hg @ 2003-05-22 07:41:20 by stephent] oldies faq <87iss3tpac.fsf@tleepslib.sk.tsukuba.ac.jp> split-string tweaks n dox <87n0hftpht.fsf@tleepslib.sk.tsukuba.ac.jp> missed commit of broken-sun.h <87r878ihhf.fsf@tleepslib.sk.tsukuba.ac.jp> already loaded message <87el2rtovc.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Thu, 22 May 2003 07:41:27 +0000
parents 0f42689481f0
children 03d9d549c3fa
comparison
equal deleted inserted replaced
1494:210683f31426 1495:c3cf7db99b98
770 @result{} 32 770 @result{} 32
771 @end group 771 @end group
772 @end example 772 @end example
773 @end defun 773 @end defun
774 774
775 @defun split-string string &optional pattern 775 The function @code{split-string} can be used to parse a string into
776 This function splits @var{string} to substrings delimited by 776 components delimited by text matching a regular expression.
777 @var{pattern}, and returns a list of substrings. If @var{pattern} is 777
778 omitted, it defaults to @samp{[ \f\t\n\r\v]+}, which means that it 778 @defvar split-string-default-separators
779 splits @var{string} by white--space. 779 The default value of @var{separators} for @code{split-string}, initially
780 780 @samp{"[ \f\t\n\r\v]+"}.
781 @example 781 @end defvar
782 @group 782
783 (split-string "foo bar") 783 @defun split-string string &optional separators omit-nulls
784 This function splits @var{string} into substrings delimited by matches
785 for the regular expression @var{separators}. Each match for
786 @var{separators} defines a splitting point; the substrings between the
787 splitting points are made into a list, which is the value returned by
788 @code{split-string}. If @var{omit-nulls} is @code{t}, null strings will
789 be removed from the result list. Otherwise, null strings are left in
790 the result. If @var{separators} is @code{nil} (or omitted), the default
791 is the value of @code{split-string-default-separators}.
792
793 As a special case, when @var{separators} is @code{nil} (or omitted),
794 null strings are always omitted from the result. Thus:
795
796 @example
797 (split-string " two words ")
798 @result{} ("two" "words")
799 @end example
800
801 The result is not @samp{("" "two" "words" "")}, which would rarely be
802 useful. If you need such a result, use an explict value for
803 @var{separators}:
804
805 @example
806 (split-string " two words " split-string-default-separators)
807 @result{} ("" "two" "words" "")
808 @end example
809
810 A few examples (there are more in the regression tests):
811
812 @example
813 @group
814 (split-string "foo" "")
815 @result{} ("" "f" "o" "o" "")
816 @end group
817 @group
818 (split-string "foo" "^")
819 @result{} ("" "foo")
820 @end group
821 @group
822 (split-string "foo" "$")
823 @result{} ("foo" ""))
824 @end group
825 @group
826 (split-string "foo,bar" ",")
784 @result{} ("foo" "bar") 827 @result{} ("foo" "bar")
785 @end group 828 @end group
786 829 @group
787 @group 830 (split-string ",foo,bar," ",")
788 (split-string "something") 831 @result{} ("" "foo" "bar" "")
789 @result{} ("something") 832 @end group
790 @end group 833 @group
791 834 (split-string ",foo,bar," "^,")
792 @group 835 @result{} ("" "foo,bar,")
793 (split-string "a:b:c" ":") 836 @end group
794 @result{} ("a" "b" "c") 837 @group
795 @end group 838 (split-string "foo,bar" "," t)
796 839 @result{} ("foo" "bar")
797 @group 840 @end group
798 (split-string ":a::b:c" ":") 841 @group
799 @result{} ("" "a" "" "b" "c") 842 (split-string ",foo,bar," "," t)
843 @result{} ("foo" "bar")
800 @end group 844 @end group
801 @end example 845 @end example
802 @end defun 846 @end defun
803 847
804 @defun split-path path 848 @defun split-path path