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
|
<h3 class="section">Conversion of Characters and Strings</h3> <p>This section describes functions for converting between characters, strings and integers. <code>format</code> (see <a href="formatting-strings">Formatting Strings</a>) and <code>prin1-to-string</code> (see <a href="output-functions">Output Functions</a>) can also convert Lisp objects into strings. <code>read-from-string</code> (see <a href="input-functions">Input Functions</a>) can convert a string representation of a Lisp object into an object. The functions <code>string-to-multibyte</code> and <code>string-to-unibyte</code> convert the text representation of a string (see <a href="converting-representations">Converting Representations</a>). </p> <p>See <a href="documentation">Documentation</a>, for functions that produce textual descriptions of text characters and general input events (<code>single-key-description</code> and <code>text-char-description</code>). These are used primarily for making help messages. </p> <dl> <dt id="number-to-string">Function: <strong>number-to-string</strong> <em>number</em>
</dt> <dd>
<p>This function returns a string consisting of the printed base-ten representation of <var>number</var>. The returned value starts with a minus sign if the argument is negative. </p> <div class="example"> <pre class="example">(number-to-string 256)
⇒ "256"
</pre>
<pre class="example">(number-to-string -23)
⇒ "-23"
</pre>
<pre class="example">(number-to-string -23.5)
⇒ "-23.5"
</pre>
</div> <p><code>int-to-string</code> is a semi-obsolete alias for this function. </p> <p>See also the function <code>format</code> in <a href="formatting-strings">Formatting Strings</a>. </p>
</dd>
</dl> <dl> <dt id="string-to-number">Function: <strong>string-to-number</strong> <em>string &optional base</em>
</dt> <dd>
<p>This function returns the numeric value of the characters in <var>string</var>. If <var>base</var> is non-<code>nil</code>, it must be an integer between 2 and 16 (inclusive), and integers are converted in that base. If <var>base</var> is <code>nil</code>, then base ten is used. Floating-point conversion only works in base ten; we have not implemented other radices for floating-point numbers, because that would be much more work and does not seem useful. </p> <p>The parsing skips spaces and tabs at the beginning of <var>string</var>, then reads as much of <var>string</var> as it can interpret as a number in the given base. (On some systems it ignores other whitespace at the beginning, not just spaces and tabs.) If <var>string</var> cannot be interpreted as a number, this function returns 0. </p> <div class="example"> <pre class="example">(string-to-number "256")
⇒ 256
(string-to-number "25 is a perfect square.")
⇒ 25
(string-to-number "X256")
⇒ 0
(string-to-number "-4.5")
⇒ -4.5
(string-to-number "1e5")
⇒ 100000.0
</pre>
</div> <p><code>string-to-int</code> is an obsolete alias for this function. </p>
</dd>
</dl> <dl> <dt id="char-to-string">Function: <strong>char-to-string</strong> <em>character</em>
</dt> <dd>
<p>This function returns a new string containing one character, <var>character</var>. This function is semi-obsolete because the function <code>string</code> is more general. See <a href="creating-strings">Creating Strings</a>. </p>
</dd>
</dl> <dl> <dt id="string-to-char">Function: <strong>string-to-char</strong> <em>string</em>
</dt> <dd><p>This function returns the first character in <var>string</var>. This mostly identical to <code>(aref string 0)</code>, except that it returns 0 if the string is empty. (The value is also 0 when the first character of <var>string</var> is the null character, <acronym>ASCII</acronym> code 0.) This function may be eliminated in the future if it does not seem useful enough to retain. </p></dd>
</dl> <p>Here are some other functions that can convert to or from a string: </p> <dl compact> <dt><code>concat</code></dt> <dd>
<p>This function converts a vector or a list into a string. See <a href="creating-strings">Creating Strings</a>. </p> </dd> <dt><code>vconcat</code></dt> <dd>
<p>This function converts a string into a vector. See <a href="vector-functions">Vector Functions</a>. </p> </dd> <dt><code>append</code></dt> <dd>
<p>This function converts a string into a list. See <a href="building-lists">Building Lists</a>. </p> </dd> <dt><code>byte-to-string</code></dt> <dd><p>This function converts a byte of character data into a unibyte string. See <a href="converting-representations">Converting Representations</a>. </p></dd> </dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/String-Conversion.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/String-Conversion.html</a>
</p>
</div>
|