Files
XCEngine/docs/api/containers/string/size.md
ssdfasd 8df04c120f docs: 更新 API 文档 - 多模块修复和完善
- audio: 更新 audio-system 方法文档
- components: 新增 audio-listener/audio-source 组件方法文档,新增 remove-component 方法
- core: 更新 filewriter, types 文档
- math: 更新 box 方法文档
- memory: 更新 proxy-allocator 文档
- resources: 更新 loader 和 texture 文档
- rhi: 更新 opengl 设备、shader、swap-chain 文档
- threading: 更新 mutex 和 task-system 文档
2026-03-26 01:58:45 +08:00

45 lines
1.1 KiB
Markdown

# String::Length / Capacity / Empty
```cpp
SizeType Length() const;
SizeType Capacity() const;
bool Empty() const;
```
获取字符串的长度、容量和判空状态。
**参数:**
**返回:**
- `Length()` - 返回字符串的字符数(不包括终止 null 字符)
- `Capacity()` - 返回已分配的存储容量
- `Empty()` - 如果字符串为空则返回 `true`
**复杂度:** 均为 O(1)
**示例:**
```cpp
#include "XCEngine/Core/Containers/String.h"
#include <iostream>
int main() {
XCEngine::Containers::String s1;
std::cout << "Empty: " << s1.Empty() << std::endl; // 输出: Empty: 1
XCEngine::Containers::String s2("Hello");
std::cout << "Length: " << s2.Length() << std::endl; // 输出: Length: 5
std::cout << "Capacity: " << s2.Capacity() << std::endl; // 输出: Capacity: 6 或更大
s2.Reserve(100);
std::cout << "After Reserve(100), Capacity: " << s2.Capacity() << std::endl; // 输出: 100
return 0;
}
```
## 相关文档
- [String 总览](string.md) - 返回类总览
- [CStr](cstr.md) - 获取 C 字符串
- [Reserve / Resize](reserve-resize.md) - 内存管理