# 4.4 修改字符串

本章你可以学到修改字符串内容的知识。相关知识查阅可变形章节。

修改已存在字符串内容的最基本的函数是 aset（详情查阅数组函数）。(aset string idx char) 将字符 char 储存到字符串的 idx 位。每个字符可能是单字节的也可能是多字节的。而且如果字符使用的字节数和原字节不同，那么aset会抛出一个错误。

更强大函数有: store-substring:

Function: store-substring string index obj\
&#x20; 这个函数将 obj 储存在 索引 idx 处。参数 obj 既可以是字符，也可以是字符串。

&#x20; 由于字符串的长度是不可变的，当 obj 不符合字符串的实际长度，或任何字符采用了和原字符串不同的编码时，这个函数都会抛出一个错误。

Function: clear-string string\
&#x20; 这个函数将 string  设置为单字节字符串，同时将其内容清零。这个函数可能会改变字符串的长度。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emacs-lisp.ivory.cafe/zi-fu-chuan-he-zi-fu/xiu-gai-zi-fu-chuan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
