StrLib: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page with "== Description == A string library LogicLib string-test operators and string transformation macros. == Minimum Requirements == * NSIS 3.0 (Unicode) * Windows 2000 / Windows Vista for the <code>${Slugify}</code> macro == Logical Operators == LogicLib extensions for string prefix, suffix and substring tests. Usage: All standard LogicLib flow operators work automatically: <code>If</code>, <code>IfNot</code>, <code>Unless</code>, <code>ElseIf</code>, <code>ElseIfNot</c...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 10: Line 10:
== Logical Operators ==
== Logical Operators ==
LogicLib extensions for string prefix, suffix and substring tests.
LogicLib extensions for string prefix, suffix and substring tests.
Usage:


All standard LogicLib flow operators work automatically:
All standard LogicLib flow operators work automatically:
Line 21: Line 19:
       DetailPrint "Haystack starts with Needle"
       DetailPrint "Haystack starts with Needle"
     ${EndIf}
     ${EndIf}
 
   
     ${IfNot} $FileName ${EndsWith} ".tmp"
     ${IfNot} $FileName ${EndsWith} ".tmp"
       DetailPrint "Not a temp file"
       DetailPrint "Not a temp file"
     ${EndIf}
     ${EndIf}
 
   
     ${If} $Path ${Contains} "temp"
     ${If} $Path ${Contains} "temp"
       DetailPrint "Path contains temp"
       DetailPrint "Path contains temp"
Line 32: Line 30:
     ${EndIf}
     ${EndIf}


Case-sensitive tests (S suffix, like StrCmpS):
Case-sensitive tests (S suffix, like <code>StrCmpS</code>):


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



Latest revision as of 23:01, 27 February 2026

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