Explore My Other Channel for More Cool and Valuable Insights
π Youtube Learn Tech Tipsπ Tiktok
π Facebook:CStringArray is a one of array of CString
Using my source code with split function, you can easy do it.
Test txt File:
Excel
C#
C++
Photoshop
learn-tech-tips
programming language
Source Code:
/* *********************************************************************
 * Developer: Zidane (huuvi168@gmail.com)
 * Last Modified: 2015-10-01
 * ********************************************************************/
void CMyReadFile::split(LPCTSTR szString, TCHAR chrPattern, CStringArray &csString)
{
 
        // Pointer to find separate string, spacer by chrPattern
        TCHAR szBuffer[1024] = {0};
        LPCTSTR pFirst, pNext;
 
        // Empty buffer
        csString.RemoveAll();
 
        // Pointed to ahead
        pFirst = szString;
 
        // Find the pattern to separate each string
        while (pFirst && lstrlen(pFirst))
        {
                    pNext = StrChr(pFirst, chrPattern);
                    if (pNext)
                    {
                                lstrcpyn(szBuffer, pFirst, pNext - pFirst + 1);
                                pFirst = pNext + 1;
                    }
                    else
                    {
                                lstrcpy(szBuffer, pFirst);
                                pFirst = pNext;
                    }
 
                    // Add to list
                    csString.Add(szBuffer);
        }
 
}
 
Using Function:
void CDemoAPIDlg::OnBnClickedButtonShow()
{
   // TODO: Add your control notification handler code here
 
   wchar_t szPathToExe[MAX_PATH];
   GetModuleFileNameW(NULL, szPathToExe, MAX_PATH);
   PathRemoveFileSpec(szPathToExe); 
 
   CString szPathToFile = (CString)szPathToExe +  L"\\test.txt";
   CString szTemp = CMyReadFile::readFileText(szPathToFile);
   CStringArray csString;
   CMyReadFile::split(szTemp, L'\r\n', csString);
   for (int i=0; i<csString.GetCount(); i++)
        AfxMessageBox(csString[i]);
 
}
On this tutorial, I have Read File Text function. This function I had showed on this topic.
If you have any feedback for How to split CString to CStringArray. Leave your comment! We can discuss about it!
	Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about 
	   A Tutorial on Converting a CString to a CStringArray   , 
	please share them in the comments below. I would love to hear from you and discuss this topic further  
 
	
 
✋✋✋✋ 
		Webzone Tech Tips, all things Tech Tips for web development
		 - I am Zidane, See you next time soon ✋✋✋✋ 
	
 
