Advertisement
ASP_Volume3 String Manipulation #65156

String Compare Logical Demo

The code is used to demonstrate the usage of API function StrCmpLogicalW (Shlwapi.dll). It will help you to sort a string array by comparing them logically. The result will sort the result logically, eg, "music9.dat" is lower than "music10.dat".

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
' wrapper to StrCmpLogicalP
' given input two string
Public Function StrCmpLogical(str1 As String, str2 As String) As Long
  StrCmpLogical = StrCmpLogicalP(ByVal StrPtr(str1), ByVal StrPtr(str2))
End Function
' wrapper to two string swap
Public Sub StrSwap(str1 As String, str2 As String)
  Dim ptr As Long
  CopyMemory ptr, ByVal VarPtr(str1), 4
  CopyMemory ByVal VarPtr(str1), ByVal VarPtr(str2), 4
  CopyMemory ByVal VarPtr(str2), ptr, 4
End Sub
' to sort logically an array of string, strArray,
' starting from lower index, lowerB,
' end at upper index, upperB
Public Sub StrQSortLogical(strArray() As String, lowerB As Long, upperB As Long)
 Dim i As Long
 Dim j As Long
 Dim X As Long
 Dim Y As Long
 i = lowerB
 j = upperB
 X = StrPtr(strArray((lowerB + upperB) / 2))
 
 Do While (i <= j)
  Do While (StrCmpLogicalP(ByVal StrPtr(strArray(i)), ByVal X) < 0 And i < upperB)
   i = i + 1
  Loop
  Do While (StrCmpLogicalP(ByVal X, ByVal StrPtr(strArray(j))) < 0 And j > lowerB)
   j = j - 1
  Loop
  
  ' The Actual swapping is here
  If (i <= j) Then
   CopyMemory Y, ByVal VarPtr(strArray(i)), 4
   CopyMemory ByVal VarPtr(strArray(i)), ByVal VarPtr(strArray(j)), 4
   CopyMemory ByVal VarPtr(strArray(j)), Y, 4
   i = i + 1
   j = j - 1
  End If
 Loop
 If (lowerB < j) Then Call StrQSortLogical(strArray, lowerB, j)
 If (i < upperB) Then Call StrQSortLogical(strArray, i, upperB)
End Sub
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine