WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

String Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

String Compare

 Keywords: String Binary Compare Operators Comparison Specia Characters 

; (Both functions use multiple exit points
; to improve performance.  Many consider this
; bad programming style.)

; String comparison using BinaryCompare
#DefineFunction StrEqual(text1,text2)
   nLen1 =  StrLen(text1)
   nLen2 =  StrLen(text2)

   ; Only need to compare strings of the same length.
   If nLen1 == nLen2

      ; Passing a zero length causes a
      ; BinaryCompare error.
      If nLen1 == 0 Then Return @TRUE
      buf1 = BinaryAlloc(nLen1)
      buf2 = BinaryAlloc(nLen2)

      BinaryPokeStr(buf1, 0, text1)
      BinaryPokeStr(buf2, 0, text2)

      ; The 5th parameter is the number of
      ; bytes to compare so use string length
      rc = BinaryCompare(buf1, 0, buf2, 0, nLen1)

      buf1 = BinaryFree(buf1)
      buf2 = BinaryFree(buf2)
      Return rc
   EndIf
   Return @FALSE
#EndFunction

; String comparison using StrIndex
#DefineFunction StrEqualAlt(text1,text2)
   nLen1 =  StrLen(text1)
   nLen2 =  StrLen(text2)

   ; Only need to compare strings of the same length.
   If nLen1 == nLen2

      ; Prevent StrIndex from reporting two
      ; empty strings as not equal.
      If nLen1 == 0 Then Return @TRUE
      Return StrIndex( text1, text2, 1, @FWDSCAN)
   EndIf
   Return @FALSE
#EndFunction

; Test StrEqualAlt
strOne = "ß"
strTwo = "ss"
If StrEqualAlt(strOne, strTwo) Then strAns = "Ja"
Else strAns = "Nein"
Message(strOne:" entspricht ":strTwo:"?", strAns)

Article ID:   W18391
Filename:   String Compare.txt
File Created: 2008:04:28:07:22:30
Last Updated: 2008:04:28:07:22:30