How to split data of the CString type in MFC and that of the cstring type in mfc
[It is easy to learn, but it is inevitable that there are some mistakes. If there are any errors, please advise]
There is a library function Tokenize () in MFC ();
Function prototype: CStringT Tokenize (PCXSTR pszTokens, int & iStart) const;
This function can be used to separate CString characters.
Set the buffer beforehand. The split string requires a buffer for storage, such as a container or character array.
If you do not know how many segments will be divided, we recommend using a container or dynamic character array as a buffer zone.
The number of cycles is the number of paragraphs to be divided. For example, if you want to divide the number into three segments, Set 3.
Example:
1 CString str = "abc, def, ghi"; // the string to be split. 2 vector <CString> Temp; // each part after the split, 3 int pos = 0 in the container, respectively. // tag parameter 4 for (int I = 0; I <3; I ++) 5 {6 Temp required by the function. push_back (str. tokenize (","), pos); 7 // if each element in temp is output, abc def ghi8 is output respectively}
Output result:
Cout <Temp [0] <endl; cout <Temp [1] <endl; cout <Temp [2] <endl; // print: abc // def // ghi