Solved

Search CComBSTR for specified Text.

Posted on 2004-04-15
6
838 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now