Solved

Search CComBSTR for specified Text.

Posted on 2004-04-15
6
841 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 clear a vector as well as how to detect empty vectors in C++.
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.

770 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