strstr, _mbsstr, wcsstr

From RAD Studio
Jump to: navigation, search

Go Up to string.h Index


Header File

string.h

Category

C++ Prototyped Routines, Memory and String Manipulation Routines

Prototype

char *strstr(const char *s1, const char *s2); /* C only */

const char *strstr(const char *s1, const char *s2); // C++ only

char *strstr(char *s1, const char *s2); // C++ only

wchar_t * wcsstr(const wchar_t *s1, const wchar_t *s2);

unsigned char * _mbsstr(const unsigned char *s1, const unsigned char *s2);

Description

Scans a string for the occurrence of a given substring.

strstr scans s1 for the first occurrence of the substring s2.

Return Value

strstr returns a pointer to the element in s1, where s2 begins (points to s2 in s1). If s2 does not occur in s1, strstr returns null.

Example

#include <stdio.h>
#include <string.h>
int main(void)
{
   char *str1 = "CBuilder", *str2 = "nation", *ptr;
   ptr = strstr(str1, str2);
   printf("The substring is: %s\n", ptr);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

strstr

+

+

+

+

_mbsstr

+

wcsstr

+

+

+