如何在不同的标志切断绳子
How to cut string at various signs
本文关键字:标志 更新时间:2023-10-16
我有以下问题:我从。csv文件中读取WinCC变量。现在有一个包含ip地址的字符串。它看起来像这样:I0043CTRL/CALH1$ST$Beh$stVal;Len=4;MMSType=133;Flag=RW
本例中Address为I0043
。
现在我想截断地址后面的字符串,但是变量的名称有更多可能,例如I0043PROT/...
。
是否有可能告诉例如getline结束在不同的标志?如:getline(tmp_stringstream,tmp_string, 'C' || 'P');
谢谢帕特里克
boost::split
做你需要的:http://www.boost.org/doc/libs/1_53_0/doc/html/string_algo/usage.html#idp163440592
std::string mystring("asd,ff.erw qewr");
std::vector<std::string> tokens;
boost::split( tokens, mystring, boost::is_any_of(",.-/ ") );
在C运行库中有一个字符串标记器函数,strtok(包括
在c++运行时中有一个等效的std::strtok(包括<装运箱>)装运箱>
您可以使用std::string::find_first_of
和std::string::substr
:
string line("I0043CTRL/CALH1$ST$Beh$stVal;Len=4;MMSType=133;Flag=RW");
cout << line.substr(0, line.find_first_of("CP"));
输出:I0043
相关文章:
- 即使使用调试编译标志,表达式也是"optimized out"
- 在 CMake 中为每个目标设置编译器/链接器标志
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 在轮班操作后使用携带标志
- 如何找出引入AVX标志的内容
- I2C 文件描述符上的 I2C 总线可写/可读标志
- C ++是否有C ++ 17 OSX 10.13.6的标志
- 每次使用带有LOCK_EX标志的LOCK_NB时,相同的程序/进程都会获取锁
- CMake 3.5 中的链接器标志位置
- 如何使用 gnu gcc 标志 -mpc32、-mpc64 和 -mpc80?
- 在 CMake 中添加全局编译标志
- -Wlifetime 标志的目的是什么?
- Visual Studio 19-17 库兼容性根据 GL 标志
- 标志 |= f == s[i],这个语句会做什么?
- Visual Studio 中是否有来自代码块的编译器标志的类似物?
- 如何在 clang 的自动会议中检查支持编译标志
- 使用 boost::p rogram_options 指定多个标志
- 如何告诉 gcc 显示您使用的优化标志列表
- 生成文件中隐式规则中的 -c 标志出错
- 如何将编译器标志限制为仅(我的)本地库?