System Grab Bag

View all man pages from Linux (or from all projects)

Name

strstr, strcasestr - locate a substring

Library

Standard C library ( libc ", " -lc )

Synopsis

#include <string.h> 
char *strstr(const char *" haystack ", const char * needle );
"#define(7)_GNU_SOURCE" " /* See feature_test_macros */" #include <string.h> char *strcasestr(const char *" haystack ", const char * needle );

Description

The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating null bytes ('\e0') are not compared.

The strcasestr() function is like strstr() but ignores the case of both arguments.

Return Value

These functions return a pointer to the beginning of the located substring, or NULL if the substring is not found.

If needle is the empty string, the return value is always haystack itself.

Attributes

For an explanation of the terms used in this section, see attributes(7). allbox; lbx lb lb T{ strstr()T{ strcasestr()
InterfaceAttributeValue
T}Thread safetyMT-Safe
T}Thread safetyMT-Safe locale

Standards

strstr() C11, POSIX.1-2008.

strcasestr() GNU.

History

strstr() POSIX.1-2001, C89.

strcasestr() GNU.

See Also

  1. memchr(3),
  2. memmem(3),
  3. strcasecmp(3),
  4. strchr(3),
  5. string(3),
  6. strpbrk(3),
  7. strsep(3),
  8. strspn(3),
  9. strtok(3),
  10. wcsstr(3)