Chapter Contents |
Previous |
Next |
strrspn |
Portability: | SAS/C extension |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <lcstring.h> size_t strrspn(const char *str, const char *cset);
DESCRIPTION |
strrspn
locates the last character in the input string
str
not contained in the search set
cset
. The
strrspn
function is the reverse
of
strspn
.
RETURN VALUE |
strrspn
returns the number of characters in the input string up to and including the
last occurrence of a character not in the search set.
If all characters of the input string are in the search
set, the return value is 0. If the search set is null (that is, if it contains
no characters), the return value from
strrspn
is the length of the input string.
CAUTION |
EXAMPLE |
This example uses
strrspn
to remove trailing blanks from the end of a line:
#include <lcstring.h> #include <stdio.h> #define MAXLINE 80 main() { char *line; char string[MAXLINE]; size_t i; puts("Enter a string, followed by some spaces:"); line = gets(string); /* Find the position (i) of the last character */ /* in the string that is not a blank. */ i = strrspn(line, " "); /* Check if line is a null string. */ if (i > 0) /* Set the character after the last */ /* nonblank character to the null character. */ line[i] = '\0'; else puts("The string contains only blanks."); printf("The last nonblank character in the string is %c\n", line[i-1]); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.