[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

parse a NULL- Separated string

Posted on 2003-11-10
2
Medium Priority
?
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

656 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