### 5.3 String Conversions

— Function File: bin2dec (s)

> Return the decimal number corresponding to the binary number stored in the string s. For example,

>               bin2dec ("1110")
>               => 14

> If s is a string matrix, returns a column vector of converted numbers, one per row of s. Invalid rows evaluate to NaN.

> See also: dec2hex, base2dec, dec2base, hex2dec, dec2bin.

— 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 n is 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.

> See also: bin2dec, dec2base, base2dec, hex2dec, dec2hex.

— Function File: dec2hex (n, len)

> Return the hexadecimal string corresponding to the nonnegative integer n. For example,

>               dec2hex (2748)
>               => "ABC"

> If n is 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.

> See also: hex2dec, dec2base, base2dec, bin2dec, dec2bin.

— Function File: hex2dec (s)

> Returns the integer corresponding to the hexadecimal number stored in the string s. For example,

>               hex2dec ("12B")
>               => 299
>               hex2dec ("12b")
>               => 299

> If s is a string matrix, returns a column vector of converted numbers, one per row of s. Invalid rows evaluate to NaN.

> See also: dec2hex, base2dec, dec2base, bin2dec, dec2bin.

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

> Return a string of symbols in base b corresponding to the the nonnegative integer n.

>               dec2base (123, 3)
>               => "11120"

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

> If b is a string then the characters of b are used as the symbols for the digits of n. 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.

> See also: base2dec, dec2bin, bin2dec, hex2dec, dec2hex.

— Function File: base2dec (s, b)

> Convert s from a string of digits of base b into an integer.

>               base2dec ("11120", 3)
>               => 123

> If s is a matrix, returns a column vector with one value per row of s. 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 b is a string, the characters of b are used as the symbols for the digits of s. Space (' ') may not be used as a symbol.

>               base2dec ("yyyzx", "xyz")
>               => 123

> See also: dec2base, dec2bin, bin2dec, hex2dec, dec2hex.

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

> Shift the non-blank text of s to the left, right or center of the string. If s is 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.

— Function File: str2num (s)

> Convert the string s to a number.

— Mapping Function: toascii (s)

> Return ASCII representation of s in 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 string to 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 = \a

> replaces the unprintable alert character with its printable representation.