![]() |
C - Entwicklung String-Funktionen: Zeichen ReadOnly Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer |
|
| Strings & characters | Overview |
| is, isw Routines | These routines test characters for specified conditions. |
| memchr | Finds characters in a buffer. |
| strchr, wcschr, _mbschr | Find a character in a string. |
| strpbrk, wcspbrk, _mbspbrk | Scan strings for characters in specified character sets. |
| strrchr, wcsrchr, _mbsrchr | Scan a string for the last occurrence of a character. |
| is, isw Routines These routines test characters for specified conditions.
Remarks These routines test characters for specified conditions. The is routines produce meaningful results for any integer argument from 1 (EOF) to UCHAR_MAX (0xFF), inclusive. The expected argument type is int. Warning For the is routines, passing an argument of type char may yield unpredictable results. An SBCS or MBCS single-byte character of type char with a value greater than 0x7F is negative. If a char is passed, the compiler may convert the value to a signed int or a signed long. This value may be sign-extended by the compiler, with unexpected results. The isw routines produce meaningful results for any integer value from 1 (WEOF) to 0xFFFF, inclusive. The wint_t data type is defined in WCHAR.H as an unsigned short; it can hold any wide character or the wide-character end-of-file (WEOF) value. For each of the these routines, the result of the test for the specified condition depends on the LC_CTYPE category setting of the current locale; see setlocale for more information. In the "C" locale, the test conditions for the is routines are as follows:
Subject: Character Classification Routines | Locale Routines Keywords: See also setlocale, to Function Overview |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example * Editor's note: the following
output is significantly #include <stdio.h> void main( void ) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memchr Finds characters in a buffer. void *memchr( const void *buf, int c, size_t count );
Remarks The memchr function looks for the first occurrence of c in the first count bytes of buf. It stops when it finds c or when it has checked the first count bytes. Subject: Buffer Manipulation Routines Keywords: See also _memccpy, memcmp, memcpy, memset, strchr |
||||||
| Return Value If successful, memchr returns a pointer to the first location of c in buf. Otherwise it returns NULL. Parameters
|
||||||
|
Example #include <memory.h> int ch = 'r'; void main( void ) printf( "Search char:\t%c\n",
ch ); Search char:
r |
| strchr, wcschr,
_mbschr Find a character in a string. char *strchr( const char *string, int c ); wchar_t *wcschr( const wchar_t *string, wint_t c ); unsigned char *_mbschr( const unsigned char *string, unsigned int c );
Remarks The strchr function finds the first occurrence of c in string, or it returns NULL if c is not found. The null-terminating character is included in the search. wcschr and _mbschr are wide-character and multibyte-character versions of strchr. The arguments and return value of wcschr are wide-character strings; those of _mbschr are multibyte-character strings. _mbschr recognizes multibyte-character sequences according to the multibyte code page currently in use. These three functions behave identically otherwise. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See also strcspn, strncat, strncmp, strncpy, _strnicmp, strpbrk, strrchr, strstr |
||||||||||||||||||||||||
| Return Value Each of these functions returns a pointer to the first occurrence of c in string, or NULL if c is not found. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> int ch = 'r'; char string[] = "The quick
brown dog jumps over the lazy fox"; void main( void ) printf( "String to be
searched: \n\t\t%s\n", string ); /* Search forward. */ /* Search backward. */ Search char:
r Result: last r found at position 30 |
| strpbrk, wcspbrk,
_mbspbrk Scan strings for characters in specified character sets. char *strpbrk( const char *string, const char *strCharSet ); wchar_t *wcspbrk( const wchar_t *string, const wchar_t *strCharSet ); unsigned char *_mbspbrk( const unsigned char*string, const unsigned char *strCharSet );
Remarks The strpbrk function returns a pointer to the first occurrence of a character in string that belongs to the set of characters in strCharSet. The search does not include the terminating null character. wcspbrk and _mbspbrk are wide-character and multibyte-character versions of strpbrk. The arguments and return value of wcspbrk are wide-character strings; those of _mbspbrk are multibyte-character strings. These three functions behave identically otherwise. _mbspbrk is similar to _mbscspn except that _mbspbrk returns a pointer rather than a value of type size_t. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See Also strcspn, strchr, strrchr |
||||||||||||||||||||||||
| Return Value Each of these functions returns a pointer to the first occurrence of any character from strCharSet in string, or a NULL pointer if the two string arguments have no characters in common. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> void main( void ) 2: 3 men and 2 boys ate 5 pigs 3: 2 boys ate 5 pigs 4: 5 pigs |
| strrchr, wcsrchr,
_mbsrchr Scan a string for the last occurrence of a character. char *strrchr( const char *string, int c ); char *wcsrchr( const wchar_t *string, int c ); int _mbsrchr( const unsigned char *string, unsigned int c );
Remarks The strrchr function finds the last occurrence of c (converted to char) in string. The search includes the terminating null character. wcsrchr and _mbsrchr are wide-character and multibyte-character versions of strrchr. The arguments and return value of wcsrchr are wide-character strings; those of _mbsrchr are multibyte-character strings. These three functions behave identically otherwise. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See Also strchr, strcspn, _strnicmp, strpbrk, strspn |
||||||||||||||||||||||||
| Return Value Each of these functions returns a pointer to the last occurrence of c in string, or NULL if c is not found. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> int ch = 'r'; char string[] = "The quick
brown dog jumps over the lazy fox"; void main( void ) printf( "String to be
searched: \n\t\t%s\n", string ); /* Search forward. */ /* Search backward. */ Search char:
r Result: last r found at position 30 |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |