說明:
lstrcmpi 函式可比對兩字串的大小,但不會比對字母的大小寫
引用函式庫:
Kernel32
適用系統:
Windows NT 3.1 或 Windows 95以上
函式原型:
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" ( _ ByVal lpString1 As String, _ ByVal lpString2 As String _ ) As Long
參數型態及說明:
lpString1:String 第一個要比對的字串
lpString2:String 第二個要比對的字
回傳值:
Long 若 lpString1 大於 lpString2 時,則回傳正值(1);若 lpString1 小於 lpString2 時,則回傳負值(-1);若 lpString1 等於 lpString2 時,則回傳零(0)
.NET Framework API:
System.String.Compare
System.String.Equals
VB範例:
檢視原始碼 Visual Basic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 'VB的宣告 Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" ( _ ByVal lpString1 As String, _ ByVal lpString2 As String _ ) As Long '宣告兩個String Dim str1 As String Dim str2 As String str1 = "Windows API" str2 = "windows API" Dim rtvl As Long '比較str1跟str2的大小 rtvl = lstrcmpi(str1, str2) |
RB範例:
檢視原始碼 REALBasic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 'RB的宣告 Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" ( _ lpString1 As CString, _ lpString2 As CString _ ) As Integer '宣告兩個String Dim str1 As String Dim str2 As String str1 = "Windows API" str2 = "windows API" Dim rtvl As Integer '比較str1跟str2的大小 rtvl = lstrcmpi(str1, str2) |
VB.NET範例:
檢視原始碼 VB.NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 'VB.NET的宣告 <DllImport("kernel32.dll")> _ Shared Function lstrcmpi( _ ByVal lpString1 As String, _ ByVal lpString2 As String _ ) As Integer End Function '宣告兩個String Dim str1 As String Dim str2 As String str1 = "Windows API" str2 = "windows API" Dim rtvl As Integer '比較str1跟str2的大小 rtvl = lstrcmpi(str1, str2) |
C#範例:
檢視原始碼 C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //C#的宣告 [DllImport("kernel32")] public static extern int lstrcmpi( string lpString1, string lpString2 ); //宣告兩個string string str1; string str2; str1 = "Windows API"; str2 = "windows API"; int rtvl; //比較str1跟str2的大小 rtvl = lstrcmpi(str1, str2); |
註釋:
lstrcmpi 函式不會比較字串中字母的大小寫;而 lstrcmp 函式則會