c++ - C++ 中与 Python 的 strip() 类似的功能?

标签 c++ string strip

Python 中有一个非常有用的函数叫做strip()。 . C++ 中有类似的吗?

最佳答案

我用这个:

#include <string>
#include <cctype>

std::string strip(const std::string &inpt)
{
    auto start_it = inpt.begin();
    auto end_it = inpt.rbegin();
    while (std::isspace(*start_it))
        ++start_it;
    while (std::isspace(*end_it))
        ++end_it;
    return std::string(start_it, end_it.base());
}

关于c++ - C++ 中与 Python 的 strip() 类似的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9358718/

相关文章:

c++ - 完成一个类型的数据

c - 消息 UDP 中的文件名

c# - HTML 条函数

MySQL按年/月/日排序

c# - 字符串。将字符替换为字符串

javascript - Rstrip 基于 Javascript 中的正则表达式

c++ - 任何类型的数组总是聚合吗?

python - 检测立方体和圆锥体是否相交?

c++ - main() 函数位于与我在 C++ 中的项目同名的 .cpp 文件中

从字符串中删除括号