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.
sprintf (see section Formatted Output).
setstr ([97, 98, 99])
creates the string
abc
implicit_str_to_num_ok is nonzero, implicit
conversions of strings to their numeric ASCII equivalents are allowed.
Otherwise, an error message is printed and control is returned to the
top level. The default value is 0.
bell = "\a";
assigns the value of the alert character (control-g, ASCII code 7) to the string variable bell. If this string is printed, the system will ring the terminal bell (if it is possible). This is normally the desired outcome. However, sometimes it is useful to be able to print the original representation of the string, with the special characters replaced by their escape sequences. For example,
octave:13> undo_string_escapes (bell) ans = \a
replaces the unprintable alert character with its printable representation. See section String Constants, for a description of string escapes.
bin2dec ("1110")
=> 14
dec2bin (14) => "1110"
dec2hex (2748) => "abc"
findstr ("ababab", "a")
=> [1 3 5]
findstr ("abababa", "aba", 0)
=> [1, 5]
hex2dec ("12B")
=> 299
hex2dec ("12b")
=> 299
index ("Teststring", "t")
=> 4
Note: This function does not work for arrays of strings.
rindex ("Teststring", "t")
=> 6
Note: This function does not work for arrays of strings.
split ("Test string", "t")
=> Tes
s
ring
Note: This function is modelled after MATLAB. In Octave, you can create a matrix of strings by [s_1; ...; s_n].
strrep ("This is a test string", "is", "&%$")
=> Th&%$ &%$ a test string
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)).
tolower ("MiXeD cAsE 123")
=> "mixed case 123"
toupper ("MiXeD cAsE 123")
=> "MIXED CASE 123"
toascii ("ASCII")
=> [ 65, 83, 67, 73, 73 ]
Octave also provides the following C-type character class test functions. They all operate on string arrays and return matrices of zeros and ones. Elements that are nonzero indicate that the condition was true for the corresponding character in the string array.
Go to the first, previous, next, last section, table of contents.