Tuesday, 23 August 2011

Lexical string comparison in NSIS

Standard (built-in) string comparison operators are:
  • case-insensitive: ==, !=, StrCmp
  • case-sensitive: StrCmpS

They are only capable of telling whether two strings are equal or not. They don't provide information on which string is greater or less, if strings differ.

LogicLib plug-in extends this set of comparison operators with following ones:
  • case-insensitive: <, <=, >, >=
  • case-sensitive: S==, S!=

Note that operators with capital letter S are case-sensitive.

Here are some tests:

StrCpy $0 "abc"
StrCpy $1 "abc"
StrCpy $2 "Abc"
StrCpy $3 "bbc"

${If} $0 == $1
   DetailPrint "Equal to $1"
   DetailPrint "Not equal to $1"

${If} $0 == $2
   DetailPrint "Equal to $2"
   DetailPrint "Not equal to $2"

; case sensitive comparison (LogicLib operator)
${If} $0 S== $2
   DetailPrint "Equal to $2"
   DetailPrint "Not equal to $2"

${If} $0 == $3
   DetailPrint "Equal to $3"
   DetailPrint "Not equal to $3"

${If} $0 S< $2
   DetailPrint "Less than $2"
   DetailPrint "Greater or equal than $2"

${If} $0 S< $3
   DetailPrint "Less than $3"
   DetailPrint "Greater or equal than $3"


Equal to abc.
Equal to Abc.
Not equal to Abc.
Not equal to bbc.
Greater or equal than Abc.
Less than bbc.
Post a Comment