strsect¶
Purpose¶
Extracts a substring of a string.
Format¶
-
y =
strsect
(str, start, len)¶ - Parameters
str (string or scalar) – data from which the string segment is to be obtained.
start (scalar) – the index of the substring in str. The index of the first character is 1.
len (scalar) – the length of the substring.
- Returns
y (string) – the extracted substring, or a null string if start is greater than the length of str.
Examples¶
// String to search in
strng = "This is an example string.";
// Remove section of string
y = strsect(strng, 12, 7);
The above code assigns the variable y to be:
example
Remarks¶
If there are not enough characters in a string for the defined substring to be extracted, then a short string or a null string will be returned.
If str is a matrix containing character data, it must be scalar.
See also
Functions strlen()
, strindx()
, strrindx()
, strreplace()