#include <boost/process.hpp>
#include <boost/process/extend.hpp>
#include <boost/optional.hpp>
#include <memory>
#include <utility>
template<typename TRealHandler> class
t_OptionalHandler
: public ::boost::process::extend::handler
{
private: using t_OptionalRealHandler = ::boost::optional<TRealHandler>;
private: t_OptionalRealHandler m_real_handler;
public:
t_OptionalHandler(void)
: m_real_handler{}
{}
public: explicit
t_OptionalHandler(TRealHandler && real_handler)
: m_real_handler{::std::move(real_handler)}
{}
template<typename TExecutor>
void on_setup(TExecutor & e) const
{
if(m_real_handler)
{
m_real_handler.get().on_setup(e);
}
}
template<typename TExecutor>
void on_error(TExecutor & e, const std::error_code & code) const
{
if(m_real_handler)
{
m_real_handler.get().on_error(e, code);
}
}
template<typename TExecutor>
void on_success(TExecutor & e) const
{
if(m_real_handler)
{
m_real_handler.get().on_success(e);
}
}
};
int main()
{
bool const need_to_redirect{false};
::std::unique_ptr<::boost::process::ipstream> const p_stream
{
need_to_redirect?
new ::boost::process::ipstream{}
:
nullptr
};
using t_OptionalStdOutRedirectionHandler = t_OptionalHandler
<
decltype(::boost::process::std_out > *p_stream)
>;
::boost::process::child ch
(
"cmd"
, need_to_redirect?
t_OptionalStdOutRedirectionHandler{::boost::process::std_out > *p_stream}
:
t_OptionalStdOutRedirectionHandler{}
);
ch.wait();
return(0);
}
我如何分割句子中最长的单词,例如,如果它有超过10个字符并返回String?
答案 0 :(得分:0)
使用java8 -
for iwindow in np.arange(2):
r = np.random.rand(20)
h = np.random.rand(50)
plot.create_plots(iwindow, r, h)
display(plot.run_fig)
display(plot.hist_fig)
list将包含长度大于指定长度的所有单词。
答案 1 :(得分:0)
如果我做得对,你想在每个空格分开,或者如果一个单词在索引n处有超过n个字符。尝试这样的事情:
int size = 10;
String s = "сотрудник компании ГазТехСтройСнабСервис";
String[] parts = s.split("(?<=\\G.{"+size+"})|\\s+");
System.out.println(Arrays.toString(parts));