Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search substring in to string

281 views
Skip to first unread message

Bertram

unread,
May 14, 2013, 3:45:52 PM5/14/13
to


Hi


I compile with MinGW program console write in C.

What function Win32 API, to use for search substring in to string?

Thanks in advance

Regards



Geoff

unread,
May 14, 2013, 4:29:59 PM5/14/13
to
On Tue, 14 May 2013 21:45:52 +0200, "Bertram" <nos...@nospam.org>
wrote:
IIRC, there is no Win32 API function for this. The standard C strstr()
function might be what you are looking for depending on your locale or
language.

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(STRSTR);k(DevLang-%22C%2B%2B%22)&rd=true

René König

unread,
May 14, 2013, 5:04:40 PM5/14/13
to
Am 14.05.2013 22:29, schrieb Geoff:
> IIRC, there is no Win32 API function for this. The standard C strstr()

There is, it's called StrStr:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773436.aspx

Geoff

unread,
May 14, 2013, 5:53:05 PM5/14/13
to
On Tue, 14 May 2013 23:04:40 +0200, Ren� K�nig <mu...@tbkoenig.de>
wrote:
The Shlwapi functions are deprecated.

René König

unread,
May 14, 2013, 6:37:00 PM5/14/13
to
Am 14.05.2013 23:53, schrieb Geoff:
> The Shlwapi functions are deprecated.

This is true for some PathXxx functions, StrStr is not one of them. Or
did I miss a part within the documentation that deprecates the entire
shlwapi?

Geoff

unread,
May 14, 2013, 7:42:57 PM5/14/13
to
On Wed, 15 May 2013 00:37:00 +0200, René König <mu...@tbkoenig.de>
wrote:
I've been looking for exactly that after I posted. :) Unable to find
it at this time.

I think if I were the OP working on a new project I'd be using the
std::string class and using std::string.find() anyway.

Bertram

unread,
May 16, 2013, 5:18:08 AM5/16/13
to

The question is:

What is function Win32-API, different of the strtstr, Windows use for search
substring in to string?


Regards



Geoff

unread,
May 16, 2013, 7:19:25 AM5/16/13
to
On Thu, 16 May 2013 11:18:08 +0200, "Bertram" <nos...@nospam.org>
wrote:

>
>The question is:
>
>What is function Win32-API, different of the strtstr, Windows use for search
>substring in to string?
>
>

The answer, as Ren� K�nig pointed out, is StrStr().

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773436.aspx

And StrStrI() for case-insensitive search.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773439(v=vs.85).aspx

Whether those functions are supported in MinGW is another question.

R.Wieser

unread,
May 16, 2013, 8:02:41 AM5/16/13
to
Bertram,

Pray tell, why is 'strstr' not usable for you ?

Hint: When rejecting a suggested solution its always a good idea to mention
why. What do you need that the offered solution does not give you.
if-and-when you encounter problems with it also a good idea to mention them.

Regards,
Rudy Wieser

Bertram <nos...@nospam.org> schreef in berichtnieuws
5194a457$0$37123$4faf...@reader1.news.tin.it...

Bertram

unread,
May 16, 2013, 8:00:52 AM5/16/13
to

Ok, Thanks.

Regards


Bertram

unread,
May 16, 2013, 3:31:39 PM5/16/13
to

I was looking for a more powerful function of stsrtstr.


Regards


R.Wieser

unread,
May 17, 2013, 3:29:38 AM5/17/13
to
Bertram,

> I was looking for a more powerful function of stsrtstr.

Thats not really informative I'm afraid (much too broad). "more powerful"
how ?

Must it be able to walk you dog, change the diapers on your newborn, or does
it only need to be able to drive your car ? :-)

In other words: How are *we* to know what you are looking for if you do not
tell us ? <whistle>

For instance, Geoff suggested the "StrStrI" if you needed case-insensitive
searching. But you could as well be looking for a normal case-sensitive
one, but now searching from the end of the string instead of from the begin.
Or both of them together.

Or something else altogether, who's to know ... (the answer to that is: only
you :-) )

Regards,
Rudy Wieser


-- Origional message:
Bertram <nos...@nospam.org> schreef in berichtnieuws
51953424$0$1372$4faf...@reader2.news.tin.it...

Bertram

unread,
May 17, 2013, 5:35:07 AM5/17/13
to

I mean a string search function, that displays strings also previous string
to the found, and the following line, for have, not only the found line, but
the whole context.


Regards




Deanna Earley

unread,
May 17, 2013, 6:16:39 AM5/17/13
to
You're talking about the UI?
That's entirely up to you and your application design.
StrStr() just gives you the location, it's up to you what you do with
the result.

There is no "Find display" common dialog box.

--
Deanna Earley (dee.e...@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)

R.Wieser

unread,
May 17, 2013, 10:11:32 AM5/17/13
to
Bertram,

As Deanna already mentioned, there is no "search all of this text *and* show
the results" (two completely different things!) API function available.

If you want to search a whole text than you simply have to use the suggested
'StrStr" function in a loop (the second search than starts from the end of
the current found string), untill the StrStr function returns with a "string
not found" status (result equals Zero).

How you than represent those results to your user is a whole different
matter. Depending on where you are searching in (a document ? a
text-window ?) you could simply display the character-position (subtract the
start of the searchbuffer before displaying the result!). You could also try
to decompse that character-position into a line-number and offset therein.
For a RichText box you could try to "hilite" the found words by, for
instance bolding them.

In short: When going the API way you will most unlikely find full solutions
to a problem. It means that you will (normally) have to combine several API
functions to create a solution. Thats the way it is, sorry :-\ :-)

Regards,
Rudy Wieser

P.s.
Even with my "it could be this or that" possibilities I described in my
previous post I was nowhere near to what you where looking for. Another
reason to be clear about it. <whistle>


-- Origional message
Bertram <nos...@nospam.org> schreef in berichtnieuws
5195f9d0$0$1365$4faf...@reader2.news.tin.it...

Christian ASTOR

unread,
May 17, 2013, 12:55:12 PM5/17/13
to
Bertram a �crit :
> I mean a string search function, that displays strings also previous string
> to the found, and the following line, for have, not only the found line, but
> the whole context.


Maybe FindText()...
(what Notepad uses for example)

0 new messages