KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Case-sensitive string comparison
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: July 20, 2020

In 4D language, the comparsion operators "=" and "#" are case-insensitive when comparing strings. For instance, if we have the following variables:

$str1:="hello"
$str2:="HELLO"
$bool1:=$str1=$str2
$bool2:=$str1#$str2

The value of $bool1 will be True, and the value of $bool2 will be False.

To perform a case-sensitive string comparsion, use either Character code for single-character strings or Generate digest for multi-character strings. The former returns the Unicode UTF-16 code of a character, and the latter returns the digest key of a string. For example, if we have the following variables:

$str1:="world"
$str2:="WORLD"
$str3:="world"
$bool1:=Generate digest($str1;4D digest)=Generate digest($str2;4D digest)
$bool2:=Generate digest($str1;4D digest)#Generate digest($str2;4D digest)
$bool3:=Generate digest($str1;4D digest)=Generate digest($str3;4D digest)

The value of $bool1 will be False, the value of $bool2 will be True, and the value of $bool3 will be True.