Mercurial > hg > octave-lyh
comparison scripts/strings/strrep.m @ 3426:f8dde1807dee
[project @ 2000-01-13 08:40:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 2000 08:40:53 +0000 |
parents | 4f40efa995c1 |
children | 301e0da5b455 |
comparison
equal
deleted
inserted
replaced
3425:8625164a0a39 | 3426:f8dde1807dee |
---|---|
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} strrep (@var{s}, @var{x}, @var{y}) | 21 ## @deftypefn {Function File} {} strrep (@var{s}, @var{x}, @var{y}) |
22 ## Replaces all occurrences of the substring @var{x} of the string @var{s} | 22 ## Replaces all occurrences of the substring @var{x} of the string @var{s} |
23 ## with the string @var{y}. For example, | 23 ## with the string @var{y}. For example, |
24 ## | 24 ## |
25 ## @example | 25 ## @example |
26 ## strrep ("This is a test string", "is", "&%$") | 26 ## strrep ("This is a test string", "is", "&%$") |
27 ## @result{} "Th&%$ &%$ a test string" | 27 ## @result{} "Th&%$ &%$ a test string" |
28 ## @end example | 28 ## @end example |
29 ## @end deftypefn | 29 ## @end deftypefn |
57 empty_list_elements_ok = 1; | 57 empty_list_elements_ok = 1; |
58 l_x = length (x); | 58 l_x = length (x); |
59 tmp = s (1 : ind (1) - 1); | 59 tmp = s (1 : ind (1) - 1); |
60 t = strcat (tmp, y); | 60 t = strcat (tmp, y); |
61 for k = 1 : len - 1 | 61 for k = 1 : len - 1 |
62 tmp = s (ind (k) + l_x : ind (k+1) - 1); | 62 tmp = s (ind (k) + l_x : ind (k+1) - 1); |
63 t = strcat (t, tmp, y); | 63 t = strcat (t, tmp, y); |
64 endfor | 64 endfor |
65 tmp = s (ind(len) + l_x : length (s)); | 65 tmp = s (ind(len) + l_x : length (s)); |
66 t = [t, tmp]; | 66 t = [t, tmp]; |
67 unwind_protect_cleanup | 67 unwind_protect_cleanup |
68 empty_list_elements_ok = save_empty_list_elements_ok; | 68 empty_list_elements_ok = save_empty_list_elements_ok; |