Files
XCEngine/docs/api/containers/string/substring.md
ssdfasd dc850d7739 docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
  - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
  - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
  - core: 修复 types 链接错误
  - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
  - memory: 修复头文件路径, malloc vs operator new, 新增方法文档
  - resources: 修复 Shader/Texture 链接错误
  - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00

44 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# String::Substring
```cpp
String Substring(SizeType pos, SizeType len = npos) const;
```
返回从位置 `pos` 开始、长度为 `len` 的子字符串。如果 `len` 省略或为 `npos`,则返回从 `pos` 到字符串末尾的所有字符。
**参数:**
- `pos` - 子字符串的起始位置(从 0 开始)
- `len` - 子字符串的长度,默认为 `npos`(即到字符串末尾)
**返回:** 新的 String 对象,包含指定的子字符串
**复杂度:** O(n),其中 n 为子字符串的长度
**示例:**
```cpp
#include "XCEngine/Containers/String.h"
#include <iostream>
int main() {
XCEngine::Containers::String s("Hello World");
XCEngine::Containers::String sub1 = s.Substring(6); // 从位置6到末尾
std::cout << sub1.CStr() << std::endl; // 输出: World
XCEngine::Containers::String sub2 = s.Substring(6, 5); // 从位置6开始长度5
std::cout << sub2.CStr() << std::endl; // 输出: World
XCEngine::Containers::String sub3 = s.Substring(0, 5); // 从位置0开始长度5
std::cout << sub3.CStr() << std::endl; // 输出: Hello
XCEngine::Containers::String sub4 = s.Substring(6, 100); // len超过剩余长度自动截断
std::cout << sub4.CStr() << std::endl; // 输出: World
return 0;
}
```
## 相关文档
- [String 总览](string.md) - 返回类总览