6/19/2017

tip, CString token in MFC

refer to below code.


CString selectedModel;
m_ListBoxOfConnection.GetText(sel, selectedModel);
//selectedModel = "com1,model1,base";

CString comStr;
CString modelStr;
CString optionStr;

AfxExtractSubString(comStr, selectedModel, 0, ',');
AfxExtractSubString(modelStr, selectedModel, 1, ',');
AfxExtractSubString(optionStr, selectedModel, 2, ',');


//then
//comStr = com1
//modelStr = model1
//optionStr = base


Thank you.



2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This is explained on the condition that CString is used.
    If input string is "aaa,bbb,ccc" and we want to split based on ','
    we can use AfxExtractionString function.
    Like that
    AfxExtractSubString(comStr, selectedModel, 0, ',');
    AfxExtractSubString(modelStr, selectedModel, 1, ',');
    AfxExtractSubString(optionStr, selectedModel, 2, ',');

    Then each string is stored like that

    comStr -> com1
    modelStr -> model1
    optionStr -> base

    Thank you.

    ReplyDelete