PS-Trainer C - Entwicklung
Bibliotheks-Funktionen: 2 Strings Readonly
Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer
PS-Trainer PS-Trainer

Strings & characters Overview
strncmp, wcsncmp, _mbsncmp Compare characters of two strings.
_stricmp, _wcsicmp, _mbsicmp Perform a lowercase comparison of strings.
_strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case.
strcmp, wcscmp, _mbscmp Compare strings.


_stricmp, _wcsicmp, _mbsicmp
Perform a lowercase comparison of strings.
int _stricmp( const char *string1, const char *string2 );
int _wcsicmp( const wchar_t *string1, const wchar_t *string2 );
int _mbsicmp( const unsigned char *string1, const unsigned char_t *string2 );


Routine Required Header Compatibility
 _stricmp <string.h> Win 95, Win NT
 _wcsicmp <string.h> or <wchar.h> Win 95, Win NT
 _mbsicmp <mbstring.h> Win 95, Win NT

Remarks
The _stricmp function lexicographically compares lowercase versions of string1 and string2 and returns a value indicating their relationship. _stricmp differs from _stricoll in that the _stricmp comparison is not affected by locale, whereas the _stricoll comparison is according to the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
The _strcmpi function is equivalent to _stricmp and is provided for backward compatibility only.
_wcsicmp and _mbsicmp are wide-character and multibyte-character versions of _stricmp. The arguments and return value of _wcsicmp are wide-character strings; those of _mbsicmp are multibyte-character strings. _mbsicmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.
_wcsicmp and wcscmp behave identically except that wcscmp does not convert its arguments to lowercase before comparing them. _mbsicmp and _mbscmp behave identically except that _mbscmp does not convert its arguments to lowercase before comparing them.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsicmp _stricmp _mbsicmp _wcsicmp

Subject: String Manipulation Routines
Keywords: See Also memcmp, _memicmp, strcmp, strcoll Functions, strncmp, _strnicmp, strrchr, _strset, strspn
Return Value
The (integer) return value indicates the relation of string1 to string2 as follows.
Return Value Description
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbsicmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters
string1 Null-terminated string to compare
string2 Null-terminated string to compare

Example
/* STRCMP.C */

#include <string.h>
#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";

void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}


Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox

strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2


_strnicmp, _wcsnicmp, _mbsnicmp
Compare characters of two strings without regard to case.
int _strnicmp( const char *string1, const char *string2, size_t count );
int _wcsnicmp( const wchar_t *string1, const wchar_t *string2, size_t count );
int _mbsnicmp( const unsigned char *string1, const unsigned char *string2, size_t count );


Routine Required Header Compatibility
 _strnicmp <string.h> Win 95, Win NT
 _wcsnicmp <string.h> or <wchar.h> Win 95, Win NT
 _mbsnicmp <mbstring.h> Win 95, Win NT

Remarks
The _strnicmp function lexicographically compares, at most, the first count characters of string1 and string2. The comparison is performed without regard to case;
_strnicmp is a case-insensitive version of strncmp. The comparison ends if a terminating null character is reached in either string before count characters are compared. If the strings are equal when a terminating null character is reached in either string before count characters are compared, the shorter string is lesser.
Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if it is uppercase.
_wcsnicmp and _mbsnicmp are wide-character and multibyte-character versions of _strnicmp. The arguments and return value of _wcsnicmp are wide-character strings; those of _mbsnicmp are multibyte-character strings. _mbsnicmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. For more information, see Code Pages. These three functions behave identically otherwise. These functions are not affected by the current locale setting.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsncicmp _strnicmp _mbsnicmp _wcsnicmp
_tcsncicmp _strnicmp _mbsnbicmp _wcsnicmp

Subject: String Manipulation Routines
Keywords: See Also strcat, strcmp, strcpy, strncat, strncmp, strncpy, strrchr, _strset, strspn
Return Value
The (integer) return value indicates the relationship between the substrings as follows.
Return Value Description
< 0 string1 substring less than string2 substring
0 string1 substring identical to string2 substring
> 0 string1 substring greater than string2 substring
On an error, _mbsnicmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters
string1 Null-terminated string to compare
string2 Null-terminated string to compare
count Number of characters to compare

Example
/* STRNCMP.C */
#include <string.h>
#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown fox jumps over the lazy dog";

void main( void )
{
char tmp[20];
int result;
printf( "Compare strings:\n\t\t%s\n\t\t%s\n\n", string1, string2 );
printf( "Function:\tstrncmp (first 10 characters only)\n" );
result = strncmp( string1, string2 , 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\tstrnicmp _strnicmp (first 10 characters only)\n" );
result = _strnicmp( string1, string2, 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
}


Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown fox jumps over the lazy dog

Function: strncmp (first 10 characters only)
Result: String 1 is greater than string 2

Function: _strnicmp (first 10 characters only)
Result: String 1 is equal to string 2


strncmp, wcsncmp, _mbsncmp
Compare characters of two strings.
int strncmp( const char *string1, const char *string2, size_t count );
int wcsncmp( const wchar_t *string1, const wchar_t *string2, size_t count );
int _mbsncmp( const unsigned char *string1, const unsigned char string2, size_t count );


Routine Required Header Compatibility
 strncmp <string.h> ANSI, Win 95, Win NT
 wcsncmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
 _mbsncmp <mbstring.h> Win 95, Win NT

Remarks
The strncmp function lexicographically compares, at most, the first count characters in string1 and string2 and returns a value indicating the relationship between the substrings. strncmp is a case-sensitive version of _strnicmp. Unlike strcoll, strncmp is not affected by locale. For more information on the LC_COLLATE category, see setlocale.
wcsncmp and _mbsncmp are wide-character and multibyte-character versions of strncmp. The arguments and return value of wcsncmp are wide-character strings; those of _mbsncmp are multibyte-character strings. _mbsncmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. For more information, see Code Pages. These three functions behave identically otherwise. wcsncmp and _mbsncmp are case-sensitive versions of _wcsnicmp and _mbsnicmp.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcsnccmp strncmp _mbsncmp wcsncmp
_tcsncmp strncmp _mbsnbcmp wcsncmp

Subject: String Manipulation Routines
Keywords: See Also _mbsnbcmp, _mbsnbicmp, strcmp, strcoll Functions, _strnicmp, strrchr, _strset, strspn
Return Value
The (integer) return value indicates the relation of the substrings of string1 and string2 as follows.
Return Value Description
< 0 string1 substring less than string2 substring
0 string1 substring identical to string2 substring
> 0 string1 substring greater than string2 substring
On an error, _mbsncmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters
string1 Strings to compare
string2 Strings to compare
count Number of characters to compare

Example
/* STRNCMP.C */
#include <string.h>
#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown fox jumps over the lazy dog";

void main( void )
{
char tmp[20];
int result;
printf( "Compare strings:\n\t\t%s\n\t\t%s\n\n", string1, string2 );
printf( "Function:\tstrncmp (first 10 characters only)\n" );
result = strncmp( string1, string2 , 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
printf( "Function:\tstrnicmp _strnicmp (first 10 characters only)\n" );
result = _strnicmp( string1, string2, 10 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "Result:\t\tString 1 is %s string 2\n\n", tmp );
}


Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown fox jumps over the lazy dog

Function: strncmp (first 10 characters only)
Result: String 1 is greater than string 2

Function: _strnicmp (first 10 characters only)
Result: String 1 is equal to string 2


strcmp, wcscmp, _mbscmp
Compare strings.
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );


Routine Required Header Compatibility
 strcmp <string.h> ANSI, Win 95, Win NT
 wcscmp <string.h> or <wchar.h> ANSI, Win 95, Win NT
 _mbscmp <mbstring.h> Win 95, Win NT

Remarks
The strcmp function compares string1 and string2 lexicographically and returns a value indicating their relationship.
wcscmp and _mbscmp are wide-character and multibyte-character versions of strcmp. The arguments and return value of wcscmp are wide-character strings; those of _mbscmp are multibyte-character strings. _mbscmp recognizes multibyte-character sequences according to the current multibyte code page and returns _NLSCMPERROR on an error. (For more information, see Code Pages.) These three functions behave identically otherwise.

Generic-Text Routine Mappings
TCHAR.H _UNICODE & _MBCS _MBCS _UNICODE
Routine Not Defined Defined Defined
_tcscmp strcmp _mbscmp wcscmp

The strcmp functions differ from the strcoll functions in that strcmp comparisons are not affected by locale, whereas the manner of strcoll comparisons is determined by the LC_COLLATE category of the current locale. For more information on the LC_COLLATE category, see setlocale.
In the "C" locale, the order of characters in the character set (ASCII character set) is the same as the lexicographic character order. However, in other locales, the order of characters in the character set may differ from the lexicographic order. For example, in certain European locales, the character 'a' (value 0x61) precedes the character 'ä' (value 0xE4) in the character set, but the character 'ä' precedes the character 'a' lexicographically.
In locales for which the character set and the lexicographic character order differ, use strcoll rather than strcmp for lexicographic comparison of strings according to the LC_COLLATE category setting of the current locale. Thus, to perform a lexicographic comparison of the locale in the above example, use strcoll rather than strcmp. Alternatively, you can use strxfrm on the original strings, then use strcmp on the resulting strings.
_stricmp, _wcsicmp, and _mbsicmp compare strings by first converting them to their lowercase forms.Two strings containing characters located between 'Z' and 'a' in the ASCII table ('[', '\', ']', '^', '_', and '`') compare differently, depending on their case. For example, the two strings "ABCDE" and "ABCD^" compare one way if the comparison is lowercase ("abcde" > "abcd^") and the other way ("ABCDE" < "ABCD^") if the comparison is uppercase.

Subject: String Manipulation Routines
Keywords: See Also memcmp, _memicmp, strcoll Functions, _stricmp, strncmp, _strnicmp, strrchr, strspn, strxfrm
Return Value
The (integer) return value for each of these functions indicates the lexicographic relation of string1 to string2.
Value Relationship of string1 to string2
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
On an error, _mbscmp returns _NLSCMPERROR, which is defined in STRING.H and MBSTRING.H.

Parameters
string1 Null-terminated string to compare
string2 Null-terminated string to compare

Example
/* STRCMP.C */

#include <string.h>
#include <stdio.h>

char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";

void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}


Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox

strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2


Homepage von PS-Trainer - C-Entwicklung - Strings - an PS-Trainer

Aktuelle Daten dieser Seite Letzte Änderung:
  Geocities

 

 

 

Hosted by www.Geocities.ws

1