Solved

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

Posted on 2006-06-29
11
1,116 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
[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
  • 4
  • 4
  • 3
11 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 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