| GNU Octave Manual by John W. Eaton Paperback (6"x9"), 324 pages, 4 figures ISBN 0954161726 RRP £19.99 ($29.99) |
5.2 Searching and Replacing
- Function File: deblank (s)
- Removes the trailing blanks from the string s.
- Function File: findstr (s, t, overlap)
- Return the vector of all positions in the longer of the two strings
s and t where an occurrence of the shorter of the two starts.
If the optional argument overlap is nonzero, the returned vector
can include overlapping positions (this is the default). For example,
findstr ("ababab", "a") => [ 1, 3, 5 ] findstr ("abababa", "aba", 0) => [ 1, 5 ]
- Function File: index (s, t)
- Return the position of the first occurrence of the string t in the
string s, or 0 if no occurrence is found. For example,
index ("Teststring", "t") => 4Note: This function does not work for arrays of strings.
- Function File: rindex (s, t)
- Return the position of the last occurrence of the string t in the
string s, or 0 if no occurrence is found. For example,
rindex ("Teststring", "t") => 6Note: This function does not work for arrays of strings.
- Function File: split (s, t)
- Divides the string s into pieces separated by t, returning
the result in a string array (padded with blanks to form a valid
matrix). For example,
split ("Test string", "t") => "Tes " " s " "ring"
- Function File: strcmp (s1, s2)
- Compares two strings, returning 1 if they are the same, and 0 otherwise.
Note: For compatibility with MATLAB, Octave's strcmp function returns 1 if the strings are equal, and 0 otherwise. This is just the opposite of the corresponding C library function.
- Function File: strrep (s, x, y)
- Replaces all occurrences of the substring x of the string s
with the string y. For example,
strrep ("This is a test string", "is", "&%$") => "Th&%$ &%$ a test string"
- Function File: substr (s, beg, len)
- Return the substring of s which starts at character number
beg and is len characters long. For example,
substr ("This is a test string", 6, 9) => "is a test"Note: This function is patterned after AWK. You can get the same result by
s (beg : (beg + len - 1)).
| ISBN 0954161726 | GNU Octave Manual | See the print edition |