Implement the string split function of c ++ to implement cstringsplit
Today, I wrote a program and encountered a function to implement string. split. Python, qt, and c ++. Copy one from the Internet and put it here. If you need it, you can drag it and use it directly. Otherwise, you will get rid of it when you write a small example.
For example, "aa * bb * cc" is stored as a vector <string> "aa" "bb" "cc"
// Temp1.cpp: defines the entry point of the console application.
//
# Include "stdafx. h"
# Include <iostream>
# Include <stdio. h>
# Include <string>
# Include <vector>
Using namespace std;
Int _ tmain (int argc, _ TCHAR * argv [])
{
Char a [] = "abc * 123 * xyz"; // The object is parsed to abc 123 xyz and then stored in the following variable vector <string>
String strArry =;
Vector <string> strArryList;
Size_t last = 0;
Size_t index = strArry. find_first_of ("*", last); // find the first one after the last coordinate *
While (index! = Std: string: npos) // locate a push vector until the final point is found.
{
StrArryList. push_back (strArry. substr (last, index-last ));
Last = index + 1;
Index = strArry. find_first_of ("*", last );
}
If (index-last> 0) // remember to push the last forward. Here is "xyz"
{
StrArryList. push_back (strArry. substr (last, index-last ));
}
For (int I = 0; I <strArryList. size (); I ++)
Std: cout <strArryList [I] <std: endl;
Getchar ();
Return 0;
}