StrLib

From NSIS Wiki
Jump to navigationJump to search

Description

A string library LogicLib string-test operators and string transformation macros.

Minimum Requirements

  • NSIS 3.0 (Unicode)
  • Windows 2000 / Windows Vista for the ${Slugify} macro

Logical Operators

LogicLib extensions for string prefix, suffix and substring tests.

All standard LogicLib flow operators work automatically: If, IfNot, Unless, ElseIf, ElseIfNot, ElseUnless, AndIf, AndIfNot, OrIf, OrIfNot, etc.

Case-insensitive tests:

   ${If} $Haystack ${StartsWith} $Needle
     DetailPrint "Haystack starts with Needle"
   ${EndIf}
   
   ${IfNot} $FileName ${EndsWith} ".tmp"
     DetailPrint "Not a temp file"
   ${EndIf}
   
   ${If} $Path ${Contains} "temp"
     DetailPrint "Path contains temp"
   ${ElseIf} $Path ${Contains} "cache"
     DetailPrint "Path contains cache"
   ${EndIf}

Case-sensitive tests (S suffix, like StrCmpS):

   ${If} $Haystack ${StartsWithS} "HTTP"
   ${If} $FileName ${EndsWithS} ".DLL"
   ${If} $Path ${ContainsS} "Temp"

Transformations

String transformation macros


   ${Trim}           "  hello  "        $R0   ; "hello"
   ${TrimLeft}       "  hello  "        $R0   ; "hello  "
   ${TrimRight}      "  hello  "        $R0   ; "  hello"
   
   ${PadLeft}        "hi" 5 "0"         $R0   ; "000hi"
   ${PadRight}       "hi" 5 "."         $R0   ; "hi..."
   
   ${Reverse}        "Hello"            $R0   ; "olleH"
   
   ${ToLowerCase}    "Hello World"      $R0   ; "hello world"
   ${ToUpperCase}    "Hello World"      $R0   ; "HELLO WORLD"
   ${ToCapitalCase}  "hello_world"      $R0   ; "Hello World"
   
   ${ToPascalCase}   "hello_world"      $R0   ; "HelloWorld"
   ${ToCamelCase}    "hello_world"      $R0   ; "helloWorld"
   ${ToSnakeCase}    "helloWorld"       $R0   ; "hello_world"
   ${ToConstantCase} "helloWorld"       $R0   ; "HELLO_WORLD"
   ${ToKebabCase}    "helloWorld"       $R0   ; "hello-world"
   
   ${Slugify}        "Ärger über Öl"    $R0   ; "arger-uber-ol"

All transforms support Unicode Latin characters (ö, é, ø, etc.). Slugify transliterates accented characters to ASCII equivalents.

Links