String Conversions Next: Previous: Searching and Replacing Up: Strings



String Conversions

hex2dec (s) Function File
Return the decimal number corresponding to the binary number stored in the string s. For example
          hex2dec ("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.

dec2bin (n len) Function File
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.

dec2hex (n len) Function File
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.

hex2dec (s) Function File
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.

dec2base (n b, len) Function File
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.

base2dec (s b) Function File
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
          

strjust (s ["left"|"right"|"center"]) Function File
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.

str2num (s) Function File
Convert the string s to a number.

toascii (s) Mapping Function
Return ASCII representation of s in a matrix. For example
          toascii ("ASCII")
               => [ 65 83, 67, 73, 73 ]
          
          

tolower (s) Mapping Function
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"
          

toupper (s) Built-in Function
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"
          

do_string_escapes (string) Built-in Function
Convert special characters in string to their escaped forms.

undo_string_escapes (s) Built-in Function
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.

warn_num_to_str Built-in Variable
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.

warn_str_to_num Built-in Variable
If the value of warn_str_to_num is nonzero a warning is printed for implicit conversions of strings to their numeric ASCII equivalents. For example
          "abc" + 0
               => 97 98 99
          
elicits a warning if warn_str_to_num is nonzero. The default value is 0.

warn_single_quote_string Built-in Variable
Print warning if a signle quote character is used to introduce a string constant.