StrLib: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 19: | 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 43: | 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" | ||
${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.