?
Solved

parse a NULL- Separated string

Posted on 2003-11-10
2
Medium Priority
?
448 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

764 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