1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node165.html
2023-10-25 11:23:21 +02:00

56 lines
2.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>18.1. String Access</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" String Access">
<meta name="keywords" value="clm">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<b>Common Lisp the Language, 2nd Edition</b>
<BR> <HR><A NAME=tex2html3586 HREF="node166.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3584 HREF="node164.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3578 HREF="node164.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3588 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3589 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3587 HREF="node166.html"> String Comparison</A>
<B>Up:</B> <A NAME=tex2html3585 HREF="node164.html"> Strings</A>
<B> Previous:</B> <A NAME=tex2html3579 HREF="node164.html"> Strings</A>
<HR> <P>
<H1><A NAME=SECTION002210000000000000000>18.1. String Access</A></H1>
<P>
The following functions access a single character element of a string.
<P>
<BR><b>[Function]</b><BR>
<tt>char <i>string</i> <i>index</i> <BR></tt><tt>schar <i>simple-string</i> <i>index</i></tt><P>The given <i>index</i> must be a non-negative integer less than
the length of <i>string</i>, which must be a
string. The character at position <i>index</i>
of the string is returned as a character object.
(This character will necessarily satisfy the predicate <tt>string-char-p</tt>.)
<P>
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
X3J13 voted in March 1989 (CHARACTER-PROPOSAL) <A NAME=18159>&#160;</A>
to eliminate <tt>string-char-p</tt>.
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
<P>
As with all sequences in Common Lisp, indexing is zero-origin.
For example:
<P><pre>
(char &quot;Floob-Boober-Bab-Boober-Bubs&quot; 0) => #\F
(char &quot;Floob-Boober-Bab-Boober-Bubs&quot; 1) => #\l
</pre><P>
See <tt>aref</tt> and <tt>elt</tt>. In effect,
<P><pre>
(char s j) == (aref (the string s) j)
</pre><P>
<tt>setf</tt> may be used with <tt>char</tt> to destructively replace
a character within a string.
<P>
For <tt>char</tt>, the string may be any string;
for <tt>schar</tt>, it must be a simple string.
In some implementations of Common Lisp, the function <tt>schar</tt> may
be faster than <tt>char</tt> when it is applicable.
<P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>