strchr, strrchr

strchr, strrchr — search a string for an individual character.

Syntax

strchr (string, char_as_string)
strrchr (string, char_as_string)

		

Arguments

string

Any character string.

char_as_string

A string containing the one character to be found.

Returns

The position of the char_as_string within the string, where the first character is in position zero. If the char_as_string is not found in the string, returns -1. strchr returns the first occurrence of the character in the string. strrchr returns the last occurrence of the character in the string.

Description

These functions search a string for an individual character and return the first or last occurrence of that character within the string. The characters within a string are numbered starting at zero.

Example

Gamma> strchr("apple","a");
0
Gamma> strchr("apple","r");
-1
Gamma> strchr("apple","p");
1
Gamma> strrchr("apple pie","p");
6
Gamma> 
		

See Also

strcmp, stricmp, string_split, strlen, strrev, strstr, substr