Re: Get the occurrence of a substring. by Frank
Frank
Sun Dec 14 15:05:17 CST 2003
Yep, your right, strstr is what you want, only been about 16 years since I
needed those functions :)
Frank
"Vincent Fatica" <abuse@lucky.syr.edu> wrote in message
news:3fdca3af$1@localhost...
> On Sun, 14 Dec 2003 12:22:37 -0500, "Frank Hickman"
> <fhickman_nosp@m_noblesoft.com> wrote:
>
> >You need to look into the CRT strspn library function.
>
> That won't do what he wants. Strstr() helps the most.
>
> UINT CountSubstrings(CHAR *szString, CHAR *szSubstring) {
> CHAR *p = szString;
> UINT uCount = 0;
> while ( p = strstr(p, szSubstring) ) {
> uCount++;
> p++;
> }
> return uCount;
> }
>
> >
> >"Leo Leong" <leoleong1@hotmail.com> wrote in message
> >news:exq8p8lwDHA.3196@TK2MSFTNGP11.phx.gbl...
> >> Hi,
> >>
> >> Does anybody know if C/C++ provides any functions to get the
occurrence
> >of
> >> a substring within a string? For example,
> >>
> >> Substring: "abc"
> >> Original String: "231abc643abc"
> >> Return: 2
>
> --
> - Vince