Solved

parse a NULL- Separated string

Posted on 2003-11-10
2
440 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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