Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to tokenize a comma delimited _bstr_t typed srting into a string array?

Posted on 2006-06-29
11
Medium Priority
?
1,188 Views
Last Modified: 2013-11-20
I would like someone to show me what are the "best practices" for parsing a _bstr_t string into a string array. My program works well up to the point of getting the "responseText" into a _bstr_t typed string. it shows in the MessageBox as "1,1,3,Processed OK!,00002,,,,,Succeeded,,,Qwwfdd1A3A,,,". I tried various way to parse this data into a string array but I am very clumsy at this. Can some one please help me out?

Up to the lines, below, my C++ program works just fines.
  .
  .
   _bstr_t tempStr = pXMLHTTPReq->responseText;
   MessageBox(NULL, tempStr, "readystate", MB_OK);

After the_bstr_t string is tokenized, it should look like this :

aString[0]= "1"
aString[1]= "1"
aString[2]= "3"
aString[3]= "Processed OK!"
aString[4]= "00002"
aString[5]= ""
 .
 .
aString[10]="Succeeded"
 .
 .
0
Comment
Question by:ablazso
  • 4
  • 4
  • 3
11 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1500 total points
ID: 17015037
What about just using

#include <string.h>
#include <malloc.h>


//...

   _bstr_t tempStr = pXMLHTTPReq->responseText;

   char seps[] = ",";
   char* token;
   CStringArray aString;
   char* string = strdup ( tempStr );

   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      aString.Add ( token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }

   free ( string );

?
0
 

Author Comment

by:ablazso
ID: 17015906
First of all, thanks for your suggestion.
I added the above lines of code, however I also added #include <afxcoll.h> (otherwise CStringArray would not compile), but now I have another fatal error when I try to rebuild the solution:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxv_w32.h(18): fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

What am I doing wrong?  I do not have #include <windows.h> in my code!
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17016009
have you include stdafx.h ? its having generally files

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                  // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

-MAHESH
0
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.

 

Author Comment

by:ablazso
ID: 17018211
Given the suggested tokenizer code above, what .h file should be included so that CStringArray would not com up as undfinded during comilation? Thank you for help!
0
 
LVL 86

Expert Comment

by:jkr
ID: 17018241
Just place

#include <afxcoll.h>

in your 'stdafx.h' and that should work.
0
 

Author Comment

by:ablazso
ID: 17018257
Currently I have:
#include <afxwin.h>
#include <string.h>
#include <malloc.h>
these includes in my program, so where is windows.h commng form?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17018261
include standard stdafx.h file having above include files.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17018298
ONLY include stdafx.h having above files
0
 
LVL 86

Expert Comment

by:jkr
ID: 17018356
Is that a fixed/max count of elements in the string you want to split?
0
 

Author Comment

by:ablazso
ID: 17018855
No, I just want to tokenize the tempStr string received via:
  _bstr_t tempStr = pXMLHTTPReq->responseText;
into a string array.

Incidentally I do not have stdafx.h on my system.
0
 
LVL 86

Expert Comment

by:jkr
ID: 17018898
>>Incidentally I do not have stdafx.h on my system.

You should have one in your project directory, this is one generated when you create the project. If not, there's something going seriously wrong.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

885 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