In double-quoted strings, the backslash character is used to introduce escape sequences that represent other characters. For example, ‘\n’ embeds a newline character in a double-quoted string and ‘\"’ embeds a double quote character. In single-quoted strings, backslash is not a special character. Here is an example showing the difference:
toascii ("\n") ⇒ 10 toascii ('\n') ⇒ [ 92 110 ]
Here is a table of all the escape sequences used in Octave (within double quoted strings). They are the same as those used in the C programming language.
\\
\"
\'
\0
\a
\b
\f
\n
\r
\t
\v
In a single-quoted string there is only one escape sequence: you may insert a single quote character using two single quote characters in succession. For example,
'I can''t escape' ⇒ I can't escape
In scripts the two different string types can be distinguished if necessary
by using is_dq_string
and is_sq_string
.
Return true if x is a double-quoted character string.
See also: is_sq_string, ischar.
Return true if x is a single-quoted character string.
See also: is_dq_string, ischar.