【发布时间】:2011-05-15 01:02:53
【问题描述】:
这是我的代码
// replace all new lines with string "nl"
std::string s = "Stack\nover\rflowâ€";
boost::regex expr1("(\\n)|(\\r)");
std::string fmt("nl");
std::string s2 = boost::regex_replace(s, expr, fmt);
然后用空字符串替换所有非ascii字符
boost::regex expr2("([^\x20-\x7E])")
std::string fmt2("");
std::cout << boost::regex_replace(s2, expr2, fmt2) << std::endl;
我宁愿打一个电话来替换而不是两个。
【问题讨论】:
-
我知道它不能直接回答您的问题,但我认为您应该保留两个单独的电话,因为这是两个单独的任务。
-
以下回复解决了您的问题。如果您将其标记为正确,那就太好了。