www.delorie.com/gnu/docs/octave/octave_56.html   search  
 
Buy GNU books!


GNU Octave

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 String Conversions

Function File: bin2dec (s)
Return a decimal number corresponding to the binary number represented as a string of zeros and ones. For example,

 
bin2dec ("1110")
     => 14

Function File: dec2bin (n)
Return a binary number corresponding the nonnegative decimal number n, as a string of ones and zeros. For example,

 
dec2bin (14)
     => "1110"

Function File: dec2hex (n)
Return the hexadecimal number corresponding to the nonnegative decimal number n, as a string. For example,

 
dec2hex (2748)
     => "abc"

Function File: hex2dec (s)
Return the decimal number corresponding to the hexadecimal number stored in the string s. For example,

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

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

Function File: toascii (s)
Return ASCII representation of s in a matrix. For example,

 
toascii ("ASCII")
     => [ 65, 83, 67, 73, 73 ]

Function File: 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"

Function File: 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: 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.

Built-in Variable: implicit_num_to_str_ok
If the value of implicit_num_to_str_ok is nonzero, implicit conversions of numbers to their ASCII character equivalents are allowed when strings are constructed using a mixture of strings and numbers in matrix notation. Otherwise, an error message is printed and control is returned to the top level. The default value is 0. For example,

 
[ "f", 111, 111 ]
     => "foo"

Built-in Variable: implicit_str_to_num_ok
If the value of 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003