1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<html lang="en">
<head>
<title>Escape Sequences in string constants - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Strings.html#Strings" title="Strings">
<link rel="next" href="Character-Arrays.html#Character-Arrays" title="Character Arrays">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Escape-Sequences-in-string-constants"></a>
Next: <a rel="next" accesskey="n" href="Character-Arrays.html#Character-Arrays">Character Arrays</a>,
Up: <a rel="up" accesskey="u" href="Strings.html#Strings">Strings</a>
<hr>
</div>
<h3 class="section">5.1 Escape Sequences in string constants</h3>
<p><a name="index-escape-sequence-notation-283"></a>In double-quoted strings, the backslash character is used to introduce
<dfn>escape sequences</dfn> that represent other characters. For example,
‘<samp><span class="samp">\n</span></samp>’ embeds a newline character in a double-quoted string and
‘<samp><span class="samp">\"</span></samp>’ embeds a double quote character. In single-quoted strings, backslash
is not a special character. Here is an example showing the difference:
<pre class="example"> toascii ("\n")
10
toascii ('\n')
[ 92 110 ]
</pre>
<p>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.
<dl>
<dt><code>\\</code><dd>Represents a literal backslash, ‘<samp><span class="samp">\</span></samp>’.
<br><dt><code>\"</code><dd>Represents a literal double-quote character, ‘<samp><span class="samp">"</span></samp>’.
<br><dt><code>\'</code><dd>Represents a literal single-quote character, ‘<samp><span class="samp">'</span></samp>’.
<br><dt><code>\0</code><dd>Represents the “nul” character, control-@, ASCII code 0.
<br><dt><code>\a</code><dd>Represents the “alert” character, control-g, ASCII code 7.
<br><dt><code>\b</code><dd>Represents a backspace, control-h, ASCII code 8.
<br><dt><code>\f</code><dd>Represents a formfeed, control-l, ASCII code 12.
<br><dt><code>\n</code><dd>Represents a newline, control-j, ASCII code 10.
<br><dt><code>\r</code><dd>Represents a carriage return, control-m, ASCII code 13.
<br><dt><code>\t</code><dd>Represents a horizontal tab, control-i, ASCII code 9.
<br><dt><code>\v</code><dd>Represents a vertical tab, control-k, ASCII code 11.
<!-- We don't do octal or hex this way yet. -->
<!-- @item \@var{nnn} -->
<!-- Represents the octal value @var{nnn}, where @var{nnn} are one to three -->
<!-- digits between 0 and 7. For example, the code for the ASCII ESC -->
<!-- (escape) character is @samp{\033}.@refill -->
<!-- @item \x@var{hh}@dots{} -->
<!-- Represents the hexadecimal value @var{hh}, where @var{hh} are hexadecimal -->
<!-- digits (@samp{0} through @samp{9} and either @samp{A} through @samp{F} or -->
<!-- @samp{a} through @samp{f}). Like the same construct in @sc{ansi} C, -->
<!-- the escape -->
<!-- sequence continues until the first non-hexadecimal digit is seen. However, -->
<!-- using more than two hexadecimal digits produces undefined results. (The -->
<!-- @samp{\x} escape sequence is not allowed in @sc{posix} @code{awk}.)@refill -->
</dl>
<p>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,
<pre class="example"> 'I can''t escape'
I can't escape
</pre>
</body></html>
|