Solved

parse a NULL- Separated string

Posted on 2003-11-10
2
433 Views
Last Modified: 2012-06-21
Using windows "GetOpenFileName"  with the OFN_ALLOWMULTISELECT flag set returns a null seperated string.
Is there a standard routine for parsing this to extract each filename.
0
Comment
Question by:MCofer
2 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9719684
No, there is no such standard routine. But, writing one is not too difficult:

#include <list>
#include <string>
using namespace std;

UINT GetFilesFromMultiSelect ( char* pszMultSel, list<string>& r) {

    UINT unCount = 0;
    char* pc = pszMultSel;

    while ( strlen ( pc)) {

          r.push_back ( string ( pc)); // found a file, add it to the list of files

          pc = memchr ( pc, 0); // search for the next NULL char,

          pc++; // Advance to the next file entry ('strlen()' will return 0 at the end)

          ++unCount;
    }

     return unCount;
}
0
 
LVL 3

Accepted Solution

by:
freewell earned 125 total points
ID: 9720164
MFC way for parsing.

int nCount = 0;
CString strText;

while(AfxExtractSubString(strText,pszMultiFile,nCount++,_T(0x00)) && strText.GetLength() > 0)
{
      TRACE("File %d: %s\r\n",nCount, strText);
}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now