How to split data of the CString type in MFC and that of the cstring type in mfc

Source: Internet
Author: User

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.


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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.