KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Case sensitive utility method to compare strings
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: September 4, 2012

Below is a method that compares two strings and is case sensitive.

// ----------------------------------------------------
// Method: isEqual_CaseSensitive
// Description
// Case sensitive method that checks whether two strings are equal
//
// Parameters
// $1 (text) - First string to compare
// $2 (text) - Second string to compare
// ----------------------------------------------------

C_TEXT($1;$string1)
C_TEXT($2;$string2)
C_BOOLEAN($0)
C_LONGINT($length1;$length2)

$string1:=$1
$string2:=$2
$0:=True
$length1:=Length($string1)
$length2:=Length($string2)

If ($length1=$length2)
   For ($i;1;$length1)
      If (Character code(Substring($string1;$i;1))#Character code(Substring($string2;$i;1)))
         $i:=$length1
         $0:=False
      End if
   End for
Else
   $0:=False
End if


Here is an example of how the method can be called:

C_BOOLEAN($equal)

$equal:=isEqual_CaseSensitive ("Password";"password")


In the above example, the value of $equal will be False.