![]() |
C - Entwicklung String-Funktionen: 1 String ReadOnly Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer |
|
| Strings & characters | Overview |
| strlen, wcslen, _mbslen, _mbstrlen | Get the length of a string. |
| strstr, wcsstr, _mbsstr | Find a substring. |
| strcspn, wcscspn, _mbscspn | Find a substring in a string. |
| strspn, wcsspn, _mbsspn | Find the first substring. |
| strtok, wcstok, _mbstok | Find the next token in a string. |
| strlen, wcslen,
_mbslen, _mbstrlen Get the length of a string. size_t strlen( const char *string ); size_t wcslen( const wchar_t *string ); size_t _mbslen( const unsigned char *string ); size_t _mbstrlen( const char *string );
Remarks Each of these functions returns the number of characters in string, not including the terminating null character. wcslen is a wide-character version of strlen; the argument of wcslen is a wide-character string. wcslen and strlen behave identically otherwise. Generic-Text Routine Mappings
_mbslen and _mbstrlen return the number of multibyte characters in a multibyte-character string. _mbslen recognizes multibyte-character sequences according to the multibyte code page currently in use; it does not test for multibyte-character validity. _mbstrlen tests for multibyte-character validity and recognizes multibyte-character sequences according to the LC_CTYPE category setting of the current locale. For more information about the LC_CTYPE category, see setlocale. Subject String Manipulation Routines, Locale Routines Keywords See also setlocale, strcat, strcmp, strcoll Functions, strcpy, strrchr, _strset, strspn |
|||||||||||||||||||||||||||
| Return Value Each of these functions returns the (integer) number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error. Parameter
|
|||||||||||||||||||||||||||
|
Example #include <string.h> void main( void ) |
| strstr, wcsstr,
_mbsstr Find a substring. char *strstr( const char *string, const char *strCharSet ); wchar_t *wcsstr( const wchar_t *string, const wchar_t *strCharSet ); unsigned char *_mbsstr( const unsigned char *string, const unsigned char *strCharSet );
Remarks The strstr function returns a pointer to the first occurrence of strCharSet in string. The search does not include terminating null characters. wcsstr and _mbsstr are wide-character and multibyte-character versions of strstr. The arguments and return value of wcsstr are wide-character strings; those of _mbsstr are multibyte-character strings. These three functions behave identically otherwise. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See Also strcspn, strcmp, strpbrk, strrchr, strspn |
||||||||||||||||||||||||
| Return Value Each of these functions returns a pointer to the first occurrence of strCharSet in string, or NULL if strCharSet does not appear in string. If strCharSet points to a string of zero length, the function returns string. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> char str[] = "lazy"; void main( void ) lazy found at position 36 |
| strcspn, wcscspn,
_mbscspn Find a substring in a string. size_t strcspn( const char *string, const char *strCharSet ); size_t wcscspn( const wchar_t *string, const wchar_t *strCharSet ); size_t _mbscspn( const unsigned char *string, const unsigned char *strCharSet );
Remarks The strcspn function returns the index of the first occurrence of a character in string that belongs to the set of characters in strCharSet. Terminating null characters are included in the search. wcscspn and _mbscspn are wide-character and multibyte-character versions of strcspn. The arguments of wcscspn are wide-character strings; those of _mbscspn are multibyte-character strings. These three functions behave identically otherwise. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See Also strncat, strncmp, strncpy, _strnicmp, strrchr, strspn |
||||||||||||||||||||||||
| Return Value Each of these functions returns an integer value specifying the length of the initial segment of string that consists entirely of characters not in strCharSet. If string begins with a character that is in strCharSet, the function returns 0. No return value is reserved to indicate an error. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> void main( void ) pos = strcspn( string, "abc"
); |
| strspn, wcsspn,
_mbsspn Find the first substring. size_t strspn( const char *string, const char *strCharSet ); size_t wcsspn( const wchar_t *string, const wchar_t *strCharSet ); size_t _mbsspn( const unsigned char *string, const unsigned char *strCharSet );
Remarks The strspn function returns the index of the first character in string that does not belong to the set of characters in strCharSet. The search does not include terminating null characters. wcsspn and _mbsspn are wide-character and multibyte-character versions of strspn. The arguments of wcsspn are wide-character strings; those of _mbsspn are multibyte-character strings. These three functions behave identically otherwise. Generic-Text Routine Mappings
Subject: String Manipulation Routines Keywords: See also _mbsspnp, strcspn, strncat, strncmp, strncpy, _strnicmp, strrchr |
||||||||||||||||||||||||
| Return Value strspn, wcsspn, and _mbsspn return an integer value specifying the length of the substring in string that consists entirely of characters in strCharSet. If string begins with a character not in strCharSet, the function returns 0. No return value is reserved to indicate an error. For each of these routines, no return value is reserved to indicate an error. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> void main( void ) |
| strtok, wcstok,
_mbstok Find the next token in a string. char *strtok( char *strToken, const char *strDelimit ); wchar_t *wcstok( wchar_t *strToken, const wchar_t *strDelimit ); unsigned char *_mbstok( unsigned char*strToken, const unsigned char *strDelimit );
Remarks The strtok function finds the next token in strToken. The set of characters in strDelimit specifies possible delimiters of the token to be found in strToken on the current call. wcstok and _mbstok are wide-character and multibyte-character versions of strtok. The arguments and return value of wcstok are wide-character strings; those of _mbstok are multibyte-character strings. These three functions behave identically otherwise. Generic-Text Routine Mappings
On the first call to strtok, the function skips leading delimiters and returns a pointer to the first token in strToken, terminating the token with a null character. More tokens can be broken out of the remainder of strToken by a series of calls to strtok. Each call to strtok modifies strToken by inserting a null character after the token returned by that call. To read the next token from strToken, call strtok with a NULL value for the strToken argument. The NULL strToken argument causes strtok to search for the next token in the modified strToken. The strDelimit argument can take any value from one call to the next so that the set of delimiters may vary. Warning Each of these functions uses a static variable for parsing
the string into tokens. If multiple or simultaneous calls are made to
the same function, a high potential for data corruption and inaccurate
results exists. Therefore, do not attempt to call the same function
simultaneously for different strings and be aware of calling one of
these function from within a loop where another routine may be called
that uses the same function. However, calling this function simultaneously
from multiple threads does not have undesirable effects. |
||||||||||||||||||||||||
| Return Value All of these functions return a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered. Parameters
|
||||||||||||||||||||||||
|
Example #include <string.h> char string[] = "A string\tof
,,tokens\nand some more tokens"; void main( void ) Tokens: |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |