memcmp Compare characters in two buffers.int memcmp( const void *buf1, const void *buf2, size_t count );Routine Required Header Compatibility memcmp <memory.h> or <string.h> ANSI, Win 95, Win NT For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version Return ValueThe return value indicates the relationship between the buffers.Return Value Relationship of First count Bytes of buf1 and buf2 < 0 buf1 less than buf2 0 buf1 identical to buf2 > 0 buf1 greater than buf2 Parametersbuf1First bufferbuf2Second buffercountNumber of charactersResThe memcmp function compares the first count bytes of buf1 and buf2 and returns a value indicating their relationship.Example/* MEMCMP.C: This program uses memcmp to compare * the strings named first and second. If the first * 19 bytes of the strings are equal, the program * considers the strings to be equal. */#include <string.h> #include <stdio.h>void main( void ) { char first[] = "12345678901234567890"; char second[] = "12345678901234567891"; int result; printf( "Compare '%.19s' to '%.19s':\n", first, second ); result = memcmp( first, second, 19 ); if( result < 0 ) printf( "First is less than second.\n" ); else if( result == 0 ) printf( "First is equal to second.\n" ); else if( result > 0 ) printf( "First is greater than second.\n" ); printf( "Compare '%.20s' to '%.20s':\n", first, second ); result = memcmp( first, second, 20 ); if( result < 0 ) printf( "First is less than second.\n" ); else if( result == 0 ) printf( "First is equal to second.\n" ); else if( result > 0 ) printf( "First is greater than second.\n" ); } OutputCompare '1234567890123456789' to '1234567890123456789': First is equal to second. Compare '12345678901234567890' to '12345678901234567891': First is less than second. Buffer Manipulation RoutinesSee Also _memccpy, memchr, memcpy, memset, strcmp, strncmp
Private Declare Function memcmp Lib "crtdll.dll" (buffA As Byte, BuffB As Byte, ByVal Length As Long) as Long
模块代码:Public Function memcmp(ByRef mem1 As Variant, ByRef mem2 As Variant) As Boolean If IsArray(mem1) = True And IsArray(mem2) = True Then If UBound(mem1) = UBound(mem2) Then Dim i As Long For i = 0 To UBound(mem1) If mem1(i) <> mem2(i) Then Exit Function Next memcmp = True End If Else memcmp = (mem1 = mem2) End If End Function在立即窗口中测试: ?memcmp(array(1,2,3),array(1,2,3)) ?memcmp(array(1,2,3),array(1,2,3,4))
更正一下:Public Function memcmp(ByRef mem1 As Variant, ByRef mem2 As Variant) As Boolean If IsArray(mem1) = True And IsArray(mem2) = True Then If UBound(mem1) = UBound(mem2) Then Dim i As Long For i = 0 To UBound(mem1) If mem1(i) <> mem2(i) Then Exit Function Next memcmp = True End If ElseIf VarType(mem1) = VarType(mem2) Then memcmp = (mem1 = mem2) End If End Function
Compare characters in two buffers.int memcmp( const void *buf1, const void *buf2, size_t count );Routine Required Header Compatibility
memcmp <memory.h> or <string.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return ValueThe return value indicates the relationship between the buffers.Return Value Relationship of First count Bytes of buf1 and buf2
< 0 buf1 less than buf2
0 buf1 identical to buf2
> 0 buf1 greater than buf2
Parametersbuf1First bufferbuf2Second buffercountNumber of charactersResThe memcmp function compares the first count bytes of buf1 and buf2 and returns a value indicating their relationship.Example/* MEMCMP.C: This program uses memcmp to compare
* the strings named first and second. If the first
* 19 bytes of the strings are equal, the program
* considers the strings to be equal.
*/#include <string.h>
#include <stdio.h>void main( void )
{
char first[] = "12345678901234567890";
char second[] = "12345678901234567891";
int result; printf( "Compare '%.19s' to '%.19s':\n", first, second );
result = memcmp( first, second, 19 );
if( result < 0 )
printf( "First is less than second.\n" );
else if( result == 0 )
printf( "First is equal to second.\n" );
else if( result > 0 )
printf( "First is greater than second.\n" );
printf( "Compare '%.20s' to '%.20s':\n", first, second );
result = memcmp( first, second, 20 );
if( result < 0 )
printf( "First is less than second.\n" );
else if( result == 0 )
printf( "First is equal to second.\n" );
else if( result > 0 )
printf( "First is greater than second.\n" );
}
OutputCompare '1234567890123456789' to '1234567890123456789':
First is equal to second.
Compare '12345678901234567890' to '12345678901234567891':
First is less than second.
Buffer Manipulation RoutinesSee Also _memccpy, memchr, memcpy, memset, strcmp, strncmp
没有现成 API 可用
得自己封装成 DLL ??????
Private Declare Function memcmp Lib "crtdll.dll" (buffA As Byte, BuffB As Byte, ByVal Length As Long) as Long
If IsArray(mem1) = True And IsArray(mem2) = True Then
If UBound(mem1) = UBound(mem2) Then
Dim i As Long
For i = 0 To UBound(mem1)
If mem1(i) <> mem2(i) Then Exit Function
Next
memcmp = True
End If
Else
memcmp = (mem1 = mem2)
End If
End Function在立即窗口中测试:
?memcmp(array(1,2,3),array(1,2,3))
?memcmp(array(1,2,3),array(1,2,3,4))
If IsArray(mem1) = True And IsArray(mem2) = True Then
If UBound(mem1) = UBound(mem2) Then
Dim i As Long
For i = 0 To UBound(mem1)
If mem1(i) <> mem2(i) Then Exit Function
Next
memcmp = True
End If
ElseIf VarType(mem1) = VarType(mem2) Then
memcmp = (mem1 = mem2)
End If
End Function