字符串修剪、转换、分割、连接、格式化等工具。
More...
|
| std::string | console::ltrim (std::string str) |
| | 移除字符串左侧的空白字符(空格、制表符等)。
|
| std::string | console::rtrim (std::string str) |
| | 移除字符串右侧的空白字符。
|
| std::string | console::trim (std::string str) |
| | 移除字符串两侧的空白字符。
|
| std::string | console::ltrim (std::string str, const std::string &chars) |
| | 移除字符串左侧指定的字符集合。
|
| std::string | console::rtrim (std::string str, const std::string &chars) |
| | 移除字符串右侧指定的字符集合。
|
| std::string | console::trim (std::string str, const std::string &chars) |
| | 移除字符串两侧指定的字符集合。
|
| std::string | console::upper (std::string str) |
| | 将字符串转换为大写。
|
| std::string | console::lower (std::string str) |
| | 将字符串转换为小写。
|
| std::string | console::title (std::string str) |
| | 将字符串转换为标题格式(每个单词首字母大写,其余小写)。
|
| PartitionResult | console::partition (const std::string &text, const std::string &sep) |
| | 在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。
|
| std::vector< std::string > | console::split (std::string text, const std::string &sep=" ") |
| | 以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。
|
| template<class T> |
| std::string | console::join (const std::vector< T > &vec, const std::string &sep="") |
| | 以分隔符连接容器中的字符串元素。
|
| template<class... Args> |
| std::string | console::uni_to_str (Args &&...args) |
| | 将任意多个参数转换为字符串并拼接(无分隔符)。
|
◆ join()
template<class T>
| std::string console::join |
( |
const std::vector< T > & | vec, |
|
|
const std::string & | sep = "" ) |
以分隔符连接容器中的字符串元素。
- Template Parameters
-
| T | 元素类型(必须支持输出到 std::stringstream)。 |
- Parameters
-
- Returns
- std::string 连接后的字符串。
◆ lower()
| std::string console::lower |
( |
std::string | str | ) |
|
将字符串转换为小写。
- Parameters
-
- Returns
- std::string 小写形式。
◆ ltrim() [1/2]
| std::string console::ltrim |
( |
std::string | str | ) |
|
移除字符串左侧的空白字符(空格、制表符等)。
- Parameters
-
- Returns
- std::string 处理后的新字符串。
◆ ltrim() [2/2]
| std::string console::ltrim |
( |
std::string | str, |
|
|
const std::string & | chars ) |
移除字符串左侧指定的字符集合。
- Parameters
-
| str | 要处理的字符串。 |
| chars | 要删除的字符集(只要字符出现在此集合中就被删除)。 |
- Returns
- std::string 处理后的新字符串。
◆ partition()
| PartitionResult console::partition |
( |
const std::string & | text, |
|
|
const std::string & | sep ) |
在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。
- Parameters
-
- Returns
- PartitionResult 分区结果。
- Note
- 若未找到分隔符,则 left 为原字符串,middle 和 right 为空。
◆ rtrim() [1/2]
| std::string console::rtrim |
( |
std::string | str | ) |
|
移除字符串右侧的空白字符。
- Parameters
-
- Returns
- std::string 处理后的新字符串。
◆ rtrim() [2/2]
| std::string console::rtrim |
( |
std::string | str, |
|
|
const std::string & | chars ) |
移除字符串右侧指定的字符集合。
- Parameters
-
| str | 要处理的字符串。 |
| chars | 要删除的字符集。 |
- Returns
- std::string 处理后的新字符串。
◆ split()
| std::vector< std::string > console::split |
( |
std::string | text, |
|
|
const std::string & | sep = " " ) |
以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。
- Parameters
-
| text | 要分割的字符串。 |
| sep | 分隔符,默认为空格 " "。 |
- Returns
- std::vector<std::string> 分割后的子串列表。
- Note
- 连续的分隔符会产生空字符串子串。
◆ title()
| std::string console::title |
( |
std::string | str | ) |
|
将字符串转换为标题格式(每个单词首字母大写,其余小写)。
- Parameters
-
- Returns
- std::string 标题格式的字符串。
◆ trim() [1/2]
| std::string console::trim |
( |
std::string | str | ) |
|
移除字符串两侧的空白字符。
- Parameters
-
- Returns
- std::string 处理后的新字符串。
◆ trim() [2/2]
| std::string console::trim |
( |
std::string | str, |
|
|
const std::string & | chars ) |
移除字符串两侧指定的字符集合。
- Parameters
-
| str | 要处理的字符串。 |
| chars | 要删除的字符集。 |
- Returns
- std::string 处理后的新字符串。
◆ uni_to_str()
template<class... Args>
| std::string console::uni_to_str |
( |
Args &&... | args | ) |
|
将任意多个参数转换为字符串并拼接(无分隔符)。
- Template Parameters
-
- Parameters
-
- Returns
- std::string 所有参数按顺序拼接的结果。
◆ upper()
| std::string console::upper |
( |
std::string | str | ) |
|
将字符串转换为大写。
- Parameters
-
- Returns
- std::string 大写形式。