I´ve got the following problem: I read in WinCC Variables from a .csv file. Now there is a string which contains the ip address. It looks like this: I0043CTRL/CALH1$ST$Beh$stVal;Len=4;MMSType=133;Flag=RW
The Address in this example is I0043
.
Now I want to cut the string after the address, but there are more possible name of the variabel, for example I0043PROT/...
.
Is there any possibility to tell for example getline to end at various signs? Like: getline(tmp_stringstream,tmp_string, 'C' || 'P');
Thank you
Patrick
boost::split
does what you need: 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(",.-/ ") );
In C runtime library there's a string tokenizer function, strtok (include < string.h>)
In C++ runtime there's an equivalent std::strtok (include < cstring>)
You can use std::string::find_first_of
, and 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"));
output:
I0043
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.