W3cubDocs

/Elisp

Modifying Strings

You can alter the contents of a mutable string via operations described in this section. See Mutability.

The most basic way to alter the contents of an existing string is with aset (see Array Functions). (aset string idx char) stores char into string at index idx. Each character occupies one or more bytes, and if char needs a different number of bytes from the character already present at that index, aset signals an error.

A more powerful function is store-substring:

Function: store-substring string idx obj

This function alters part of the contents of the string string, by storing obj starting at index idx. The argument obj may be either a character or a (smaller) string.

Since it is impossible to change the length of an existing string, it is an error if obj doesn’t fit within string’s actual length, or if any new character requires a different number of bytes from the character currently present at that point in string.

To clear out a string that contained a password, use clear-string:

Function: clear-string string

This makes string a unibyte string and clears its contents to zeros. It may also change string’s length.

Copyright © 1990-1996, 1998-2019 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Modifying-Strings.html