string
split
| auto start = 0U;
auto end = s.find(delim);
while (end != std::string::npos)
{
std::cout << s.substr(start, end - start) << std::endl;
start = end + delim.length();
end = s.find(delim, start);
}
std::cout << s.substr(start, end);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | std::vector<std::string_view> split(std::string_view buffer, const std::string_view delimeter = " ")
{
std::vector<std::string_view> ret{};
std::decay_t<decltype(std::string_view::npos)> pos{};
while ((pos = buffer.find(delimeter)) != std::string_view::npos)
{
const auto match = buffer.substr(0, pos);
if (!match.empty())
ret.push_back(match);
buffer = buffer.substr(pos + delimeter.size());
}
if (!buffer.empty())
ret.push_back(buffer);
return ret;
}
|
| #include <ranges>
#include <string_view>
auto split = hello
| std::ranges::views::split(' ')
| std::ranges::views::transform([](auto&& str) {
return std::string_view(&*str.begin(), std::ranges::distance(str));
});
|
https://stackoverflow.com/questions/14265581/parse-split-a-string-in-c-using-string-delimiter-standard-c
contains
| #include <boost/algorithm/string.hpp>
bool b = boost::algorithm::contains(s, t);
|
| if (s1.find(s2) != std::string::npos) {
std::cout << "found!" << '\n';
}
|
endswith, startswith
TODO