?
Solved

Search CComBSTR for specified Text.

Posted on 2004-04-15
6
Medium Priority
?
858 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 2000 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
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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

801 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