Mercurial > hg > octave-nkf
comparison scripts/strings/strfind.m @ 8442:502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Mon, 05 Jan 2009 08:11:03 +0100 |
parents | a1dbe9d80eee |
children | eb63fbe60fab |
comparison
equal
deleted
inserted
replaced
8441:cc3ac5eb6be3 | 8442:502e58a0d44f |
---|---|
24 ## If there is no such occurrence, or if @var{pattern} is longer | 24 ## If there is no such occurrence, or if @var{pattern} is longer |
25 ## than @var{str}, then @var{idx} is the empty array @code{[]}. | 25 ## than @var{str}, then @var{idx} is the empty array @code{[]}. |
26 ## | 26 ## |
27 ## If the cell array of strings @var{cellstr} is specified instead of the | 27 ## If the cell array of strings @var{cellstr} is specified instead of the |
28 ## string @var{str}, then @var{idx} is a cell array of vectors, as specified | 28 ## string @var{str}, then @var{idx} is a cell array of vectors, as specified |
29 ## above. | 29 ## above. Examples: |
30 ## @seealso{findstr, strmatch, strcmp, strncmp, strcmpi, strncmpi} | 30 ## |
31 ## @example | |
32 ## @group | |
33 ## strfind ("abababa", "aba") | |
34 ## @result{} [1, 3, 5] | |
35 ## | |
36 ## strfind (@{"abababa", "bebebe", "ab"@}, "aba") | |
37 ## @result{} ans = | |
38 ## @{ | |
39 ## [1,1] = | |
40 ## | |
41 ## 1 3 5 | |
42 ## | |
43 ## [1,2] = [](1x0) | |
44 ## [1,3] = [](1x0) | |
45 ## @} | |
46 ## @end group | |
47 ## @end example | |
48 ## @seealso{findstr, strmatch, strcmp, strncmp, strcmpi, strncmpi, find} | |
31 ## @end deftypefn | 49 ## @end deftypefn |
32 | 50 |
33 ## Author: alois schloegl <a.schloegl@ieee.org> | 51 ## Author: alois schloegl <a.schloegl@ieee.org> |
34 ## Created: 1 November 2004 | 52 ## Created: 1 November 2004 |
35 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | 53 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> |
64 while (k < lp && ! isempty (idx)) | 82 while (k < lp && ! isempty (idx)) |
65 idx = idx(text(idx + k) == pattern(++k)); | 83 idx = idx(text(idx + k) == pattern(++k)); |
66 endwhile | 84 endwhile |
67 | 85 |
68 ### endfunction | 86 ### endfunction |
87 | |
88 %!error <Invalid call to strfind> strfind (); | |
89 %!error <Invalid call to strfind> strfind ("foo", "bar", 1); | |
90 %!error <pattern must be a string value> strfind ("foo", 100); | |
91 %!error <text must be a string or cell array of string> strfind (100, "foo"); | |
92 | |
93 %!assert (strfind ("abababa", "aba"), [1, 3, 5]); | |
94 %!assert (strfind ({"abababa", "bla", "bla"}, "a"), {[1, 3, 5, 7], 3, 3}); |