Next: Character Class Functions, Previous: Searching and Replacing, Up: Strings

— Function File: **hex2dec** (`s`)

Return the decimal number corresponding to the binary number stored in the string

s. For example,hex2dec ("1110") => 14If

sis a string matrix, returns a column vector of converted numbers, one per row ofs. Invalid rows evaluate to NaN.

— Function File: **dec2bin** (`n, len`)

Return a binary number corresponding the nonnegative decimal number

n, as a string of ones and zeros. For example,dec2bin (14) => "1110"If

nis a vector, returns a string matrix, one row per value, padded with leading zeros to the width of the largest value.The optional second argument,

len, specifies the minimum number of digits in the result.

— Function File: **dec2hex** (`n, len`)

Return the hexadecimal string corresponding to the nonnegative integer

n. For example,dec2hex (2748) => "ABC"If

nis a vector, returns a string matrix, one row per value, padded with leading zeros to the width of the largest value.The optional second argument,

len, specifies the minimum number of digits in the result.

— Function File: **hex2dec** (`s`)

Returns the integer corresponding to the hexadecimal number stored in the string

s. For example,hex2dec ("12B") => 299 hex2dec ("12b") => 299If

sis a string matrix, returns a column vector of converted numbers, one per row ofs. Invalid rows evaluate to NaN.

— Function File: **dec2base** (`n, b, len`)

Return a string of symbols in base

bcorresponding to the the nonnegative integern.dec2base (123, 3) => "11120"If

nis a vector, return a string matrix with one row per value, padded with leading zeros to the width of the largest value.If

bis a string then the characters ofbare used as the symbols for the digits ofn. Space (' ') may not be used as a symbol.dec2base (123, "aei") => "eeeia"The optional third argument,

len, specifies the minimum number of digits in the result.

— Function File: **base2dec** (`s, b`)

Convert

sfrom a string of digits of basebinto an integer.base2dec ("11120", 3) => 123If

sis a matrix, returns a column vector with one value per row ofs. If a row contains invalid symbols then the corresponding value will be NaN. Rows are right-justified before converting so that trailing spaces are ignored.If

bis a string, the characters ofbare used as the symbols for the digits ofs. Space (' ') may not be used as a symbol.base2dec ("yyyzx", "xyz") => 123

— Function File: **strjust** (`s, `[`"left"|"right"|"center"`])

Shift the non-blank text of

sto the left, right or center of the string. Ifsis a string array, justify each string in the array. Null characters are replaced by blanks. If no justification is specified, then all rows are right-justified.

— Mapping Function: **toascii** (`s`)

Return ASCII representation of

sin a matrix. For example,toascii ("ASCII") => [ 65, 83, 67, 73, 73 ]

— Mapping Function: **tolower** (`s`)

Return a copy of the string

s, with each upper-case character replaced by the corresponding lower-case one; nonalphabetic characters are left unchanged. For example,tolower ("MiXeD cAsE 123") => "mixed case 123"

— Built-in Function: **toupper** (`s`)

Return a copy of the string

s, with each lower-case character replaced by the corresponding upper-case one; nonalphabetic characters are left unchanged. For example,toupper ("MiXeD cAsE 123") => "MIXED CASE 123"

— Built-in Function: **do_string_escapes** (`string`)

Convert special characters in

stringto their escaped forms.

— Built-in Function: **undo_string_escapes** (`s`)

Converts special characters in strings back to their escaped forms. For example, the expression

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 = \areplaces the unprintable alert character with its printable representation.

— Built-in Variable: **warn_num_to_str**

If the value of

`warn_num_to_str`

is nonzero, a warning is printed for implicit conversions of numbers to their ASCII character equivalents when strings are constructed using a mixture of strings and numbers in matrix notation. For example,[ "f", 111, 111 ] => "foo"elicits a warning if

`warn_num_to_str`

is nonzero. The default value is 1.