Solved

Search CComBSTR for specified Text.

Posted on 2004-04-15
6
853 Views
Last Modified: 2012-06-27
I need to search a CComBSTR myStr
for the existance of the word "GOTO"

Any suggestions?  Im new to CComBSTR.
Thanks
0
Comment
Question by:Rowdyone52
[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
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 10835797
You'd just search the 'BSTR' member like any regular UNICODE string, e.g.

CComBSTR cb;

//...

__bstr_t bstr ( ( BSTR) cb;)
wchar_t* pwsz = ( wchar_t*) bstr;

if ( wcsstr ( pwsz, L"GOTO)) {

   // string found
}

0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 10835813
BTW, that works for ANSI also:

CComBSTR cb;

//...

__bstr_t bstr ( ( BSTR) cb;)
char* psz = ( char*) bstr;

if ( strstr ( psz, "GOTO)) {

  // string found
}


'__bstr_t' is a powerful little helper class.
0
 

Author Comment

by:Rowdyone52
ID: 10835821
thanks jkr..

does GOTO need quote surrounding or just the one?

Greg
0
Technology Partners: 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!

 
LVL 86

Expert Comment

by:jkr
ID: 10835822
Argh, forgot the closing double quote for the "GOTO" string literal :o)

CComBSTR cb;

//...

__bstr_t bstr ( ( BSTR) cb;)
char* psz = ( char*) bstr;

if ( strstr ( psz, "GOTO")) {

 // string found
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 10835827
Well, seems you found the problem with the closing quote already *g*
0
 

Author Comment

by:Rowdyone52
ID: 10835828
that answers my ?

thanks!
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 article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

719 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