problem with quoted backslashes
John W. Eaton
jwe at octave.org
Mon Mar 16 10:34:57 CDT 2009
On 16-Mar-2009, Olaf Till wrote:
| Octave version: 3.0.2
|
| Please see this:
|
| octave:1> a = [char("a"), "\\\\ \n"]
| a = a\\
|
| octave:2> printf (a)
| a\\
|
| and compare with this:
|
| octave:3> a = [char(97), "\\\\ \n"]
| a = a\\
|
| octave:4> printf (a)
| a\
| octave:5>
|
| Note that in both cases variable "a" seems to have the same contents
| according to the first display, but printf (a) behaves differently.
|
| It was not so with Octave-2.1.73, where the second "printf (a)" also
| yields "a\\", which I would think preferable.
Escape sequences are processed when double-quoted strings (those
inside "") are constructed, but not when single-quoted strings (those
inside '') are constructed.
For compatibility with Matlab, single-quoted strings are special when
they are used as the format argument of {f,s,}printf functions.
For compatibility with Matlab, char(97) produces a single-quoted string.
We had to choose what to do when concatenating single- and
double-quoted strings. We chose to make them single-quoted strings.
You can get warnings when single- and double- quoted strings are
concatenated by using
warning on Octave:string-concat
jwe
More information about the Bug-octave
mailing list