c**********e 发帖数: 2007 | 1 It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
etc...... | g*****g 发帖数: 34805 | 2 The underlying code in Java is using regex. There's probably C++ regex
package doing that too.
a
【在 c**********e 的大作中提到】 : It looks that`in Java, there is a function Split which convert a string to a : string array. I wonder if we could do the same in C++. How to do the : conversion? : string MyString = "value1;value2;value3;value4;" : string[] MyStringArray = MyString.Split(';'); : MyStringArray[0] (would give value1) : MyStringArray[1] (would give value2) : etc......
| d****p 发帖数: 685 | 3 #include
std::vector tokens;
boost::split(tokens, "value1;value2;value3;value4", boost:is_any_of(";");
// now tokens[i] = "value"
a
【在 c**********e 的大作中提到】 : It looks that`in Java, there is a function Split which convert a string to a : string array. I wonder if we could do the same in C++. How to do the : conversion? : string MyString = "value1;value2;value3;value4;" : string[] MyStringArray = MyString.Split(';'); : MyStringArray[0] (would give value1) : MyStringArray[1] (would give value2) : etc......
|
|