IF a string may include several un-necessary elements, e.g., such as @, #, $,%.
How to find them and delete them?
I know this requires a loop iteration, but I do not know how to represent sth such as @, #, $,%.
If you can give me a code example, then I will be really appreciated.
STRING is a database of known and predicted protein-protein interactions. The interactions include direct (physical) and indirect (functional) associations; they stem from computational prediction, from knowledge transfer between organisms, and from interactions aggregated from other (primary) databases.
STRING is the knowledgebase and software tool for known and predicted protein-protein interactions. It includes direct (physical) and indirect (functional) associations derived from various sources, such as genomic context, high-throughput experiments, (conserved) co-expression and the literature.
The STRING database aims to integrate all known and predicted associations between proteins, including both physical interactions as well as functional associations.
The usual standard C++ approach would be the erase/remove idiom:
#include <string>
#include <algorithm>
#include <iostream>
struct OneOf {
std::string chars;
OneOf(const std::string& s) : chars(s) {}
bool operator()(char c) const {
return chars.find_first_of(c) != std::string::npos;
}
};
int main()
{
std::string s = "string with @, #, $, %";
s.erase(remove_if(s.begin(), s.end(), OneOf("@#$%")), s.end());
std::cout << s << '\n';
}
and yes, boost offers some neat ways to write it shorter, for example using boost::erase_all_regex
#include <string>
#include <iostream>
#include <boost/algorithm/string/regex.hpp>
int main()
{
std::string s = "string with @, #, $, %";
erase_all_regex(s, boost::regex("[@#$%]"));
std::cout << s << '\n';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With