> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/strings/string-functions.md).

# 字符串函数

### 常用字符串函数（C 风格，需 ）

| 函数             | 作用            |
| -------------- | ------------- |
| `strlen(s)`    | 求长度（不含 \0）    |
| `strcpy(a, b)` | 把 b 复制到 a     |
| `strcat(a, b)` | 把 b 拼接到 a 后   |
| `strcmp(a, b)` | 比较，相等返回 0     |
| `strstr(a, b)` | 查找子串，返回首次出现位置 |
| `strrev`(非标准)  | 反转字符串         |

### 大小写转换

```cpp
#include <cctype>
char c = 'a';
toupper(c);  // 转大写
tolower(c);  // 转小写
isalpha(c);  // 是否字母
isdigit(c);  // 是否数字
```

### 查找、分割、替换

```cpp
string s = "Hello World";
int p = s.find("World");          // 查找，返回下标 6
string sub = s.substr(0, 5);      // 截取，从 0 开始取 5 个
s.replace(6, 5, "GESP");          // 从下标 6 起 5 个字符替换为 "GESP"

// 分割
string t = "a,b,c";
int start = 0;
for (int i = 0; i <= t.size(); i++) {
    if (i == t.size() || t[i] == ',') {
        cout << t.substr(start, i - start) << endl;
        start = i + 1;
    }
}
```

### C++ string 常用操作

```cpp
string a = "abc", b = "def";
cout << a + b;        // 拼接 abcdef
cout << a.size();     // 长度
a.push_back('z');     // 追加字符
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/strings/string-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
