C++ 中的字符串分词器允许多个分隔符
有没有办法用多个分隔符来标记 C++ 中的字符串?在 C# 中我会这样做:
string[] tokens = "adsl, dkks; dk".Split(new [] { ",", " ", ";" }, StringSplitOptions.RemoveEmpty);
Is there a way to tokenize a string in C++ with multiple separators? In C# I would have done:
string[] tokens = "adsl, dkks; dk".Split(new [] { ",", " ", ";" }, StringSplitOptions.RemoveEmpty);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 boost::tokenizer。它支持多个分隔符。
事实上,您甚至不需要 boost::tokenizer。如果您想要的只是拆分,请使用 boost::split。该文档有一个示例:
http://www.boost.org/ doc/libs/1_42_0/doc/html/string_algo/usage.html#id1718906
Use boost::tokenizer. It supports multiple separators.
In fact, you don't really even need boost::tokenizer. If all you want is a split, use boost::split. The documentation has an example:
http://www.boost.org/doc/libs/1_42_0/doc/html/string_algo/usage.html#id1718906
像这样的事情会做:
Something like that will do:
这是我的版本(尚未经过严格测试):
Here is my version (not heavily tested (yet)):