Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strstr(3) [suse man page]

STRSTR(3)						     Linux Programmer's Manual							 STRSTR(3)

NAME
strstr, strcasestr - locate a substring SYNOPSIS
#include <string.h> char *strstr(const char *haystack, const char *needle); #define _GNU_SOURCE #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 '' characters 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 substring, or NULL if the substring is not found. CONFORMING TO
The strstr() function conforms to C89 and C99. The strcasestr() function is a nonstandard extension. BUGS
Early versions of Linux libc (like 4.5.26) would not allow an empty needle argument for strstr(). Later versions (like 4.6.27) work cor- rectly, and return haystack when needle is empty. SEE ALSO
index(3), memchr(3), rindex(3), strcasecmp(3), strchr(3), strpbrk(3), strsep(3), strspn(3), strtok(3), wcsstr(3), feature_test_macros(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2005-04-05 STRSTR(3)

Check Out this Related Man Page

STRSTR(3)						   BSD Library Functions Manual 						 STRSTR(3)

NAME
strcasestr, strcasestr_l, strnstr, strstr -- locate a substring in a string LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strcasestr(const char *s1, const char *s2); char * strnstr(const char *s1, const char *s2, size_t n); char * strstr(const char *s1, const char *s2); #include <string.h> #include <xlocale.h> char * strcasestr_l(const char *s1, const char *s2, locale_t loc); DESCRIPTION
The strstr() function locates the first occurrence of the null-terminated string s2 in the null-terminated string s1. The strcasestr() function is similar to strstr(), but ignores the case of both strings. The strnstr() function locates the first occurrence of the null-terminated string s2 in the string s1, where not more than n characters are searched. Characters that appear after a '' character are not searched. Since the strnstr() function is a FreeBSD specific API, it should only be used when portability is not a concern. While the strcasestr() function uses the current locale, the strcasestr_l() function may be passed a locale directly. See xlocale(3) for more information. RETURN VALUES
If s2 is an empty string, s1 is returned; if s2 occurs nowhere in s1, NULL is returned; otherwise a pointer to the first character of the first occurrence of s2 is returned. EXAMPLES
The following sets the pointer ptr to the "Bar Baz" portion of largestring: const char *largestring = "Foo Bar Baz"; const char *smallstring = "Bar"; char *ptr; ptr = strstr(largestring, smallstring); The following sets the pointer ptr to NULL, because only the first 4 characters of largestring are searched: const char *largestring = "Foo Bar Baz"; const char *smallstring = "Bar"; char *ptr; ptr = strnstr(largestring, smallstring, 4); SEE ALSO
memchr(3), strchr(3), strcspn(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strtok(3), wcsstr(3), xlocale(3) STANDARDS
The strstr() function conforms to ISO/IEC 9899:1990 (``ISO C90''). BSD
October 11, 2001 BSD
Man Page

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help for shell script of finding shortest substring from given string by user

please give me proper solution for finding a shortest substring from given string if string itself and first char and last char of that substr are also given by user if S="dpoaoqooroo" and FC="o" and LC="o",then shortest substr is "oo" and rest of the string is "dpoaoqroo" i have code but it is... (1 Reply)
Discussion started by: pankajd
1 Replies

2. UNIX for Dummies Questions & Answers

Verify if substring is found in string

Hi, I'm new to HP-UNIX programming(previously using C++). I am looking for an IF statement which would return TRUE if a substring is found in a string. For example, if 'header' is found in 'header_cp', the IF statement will result to true. Would appreciate any help... (1 Reply)
Discussion started by: miashaykoh
1 Replies

3. Shell Programming and Scripting

Searching a substring from a string in UNIX

Hi all. I need help with a command to locate a substring from a string. My problem is I am passing a direcotry name as a command line argument and I need to ensure that user should not pass certain directories. E.g ther are Directories under ==> /opt/projects/* which should not be passed... (3 Replies)
Discussion started by: Veenak15
3 Replies

4. UNIX for Dummies Questions & Answers

search for string and return substring

Hi, I have a file with the following contents: I need to create a script or search command that will search for this string 'ENDC' in the file. This string is unique and only occurs in one record. Once it finds the string, I would like it to return positions 101-109 ( this is the date of... (0 Replies)
Discussion started by: Lenora2009
0 Replies

5. UNIX for Dummies Questions & Answers

If statement for substring within string (korn)

Hi all, Just looking for a simple if statement that searches for a substring within a varaible, and then performs some function. Problem is that I need it to work in Korn shell $var = *string* does not work in Korn i="xxxxxx00.00yyyyy.zzzzz" want to find 00.00 (2 Replies)
Discussion started by: jgrosecl
2 Replies

6. Programming

strstr() in Solaris System

Can any one help with the function strstr() in Solaris unix. The equivalent function of strstr() in Solaris Unix. This function is working in HP Unix but not in Solaris Unix. (16 Replies)
Discussion started by: jhon1257
16 Replies