Word Functions Header

NSIS

Previous | Contents | Next

E.3 Word Functions Header

E.3.1 Introduction

Include header:

!include "WordFunc.nsh"

Call functions:

Section Install
	${WordFind} "A--H---S" "-" "+2" $R0
	; $R0="H"
SectionEnd
Section un.Install
	${WordReplace} "A--H---S" "-" "x" "+3*" $R0
	; $R0="A--HxS"
SectionEnd

E.3.2 WordFind

  • Multi-features string function.
Strings:
"[word+1][delimiter][word+2][delimiter][word+3]..."
"[delimiter][word+1][delimiter][word+2][delimiter]..."
"[delimiter][delimiter][word+1][delimiter][delimiter][delimiter]..."
"...[word-3][delimiter][word-2][delimiter][word-1]"
"...[delimiter][word-2][delimiter][word-1][delimiter]"
"...[delimiter][delimiter][word-1][delimiter][delimiter][delimiter]"

Syntax:

${WordFind} "[string]" "[delimiter]" "[E][options]" $var
"[string]"         ;[string]
                   ;  input string
"[delimiter]"      ;[delimiter]
                   ;  one or several symbols
"[E][options]"     ;[options]
                   ;  +number   : word number from start
                   ;  -number   : word number from end
                   ;  +number}  : delimiter number from start
                   ;              all space after this
                   ;              delimiter to output
                   ;  +number{  : delimiter number from start
                   ;              all space before this
                   ;              delimiter to output
                   ;  +number}} : word number from start
                   ;              all space after this word
                   ;              to output
                   ;  +number{{ : word number from start
                   ;              all space before this word
                   ;              to output
                   ;  +number{} : word number from start
                   ;              all space before and after
                   ;              this word (word exclude)
                   ;  +number*} : word number from start
                   ;              all space after this
                   ;              word to output with word
                   ;  +number{* : word number from start
                   ;              all space before this
                   ;              word to output with word
                   ;  #         : sum of words to output
                   ;  *         : sum of delimiters to output
                   ;  /word     : number of word to output
                   ;
                   ;[E]
                   ;  with errorlevel output
                   ;  IfErrors:
                   ;     $var=1  delimiter not found
                   ;     $var=2  no such word number
                   ;     $var=3  syntax error (Use: +1,-1},#,*,/word,...)
                   ;[]
                   ;  no errorlevel output (default)
                   ;  If some errors found then (result=input string)
                   ;
$var               ;output (result)

Note: - Accepted numbers 1,01,001,...

Example (Find word by number):

Section
	${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " C:\" "-02" $R0
	; $R0="Program Files"
SectionEnd

Example (Delimiter exclude):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "-2}" $R0
	; $R0=" C:\logo.sys C:\WINDOWS"
SectionEnd

Example (Sum of words):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " C:\" "#" $R0
	; $R0="3"
SectionEnd

Example (Sum of delimiters):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "*" $R0
	; $R0="2"
SectionEnd

Example (Find word number):

Section
	${WordFind} "C:\io.sys C:\Program Files C:\WINDOWS" " " "/Files" $R0
	; $R0="3"
SectionEnd

Example ( }} ):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2}}" $R0
	; $R0=" C:\WINDOWS"
SectionEnd

Example ( {} ):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2{}" $R0
	; $R0="C:\io.sys C:\WINDOWS"
SectionEnd

Example ( *} ):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "+2*}" $R0
	; $R0="C:\logo.sys C:\WINDOWS"
SectionEnd

Example (Get parent directory):

Section
	StrCpy $R0 "C:\Program Files\NSIS\NSIS.chm"
;	           "C:\Program Files\NSIS\Include\"
;	           "C:\\Program Files\\NSIS\\NSIS.chm"

	${WordFind} "$R0" "\" "-2{*" $R0
	; $R0="C:\Program Files\NSIS"
	;     "C:\\Program Files\\NSIS"
SectionEnd

Example (Coordinates):

Section
	${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" ":\lo" "E+1{" $R0
	; $R0="C:\io.sys C"
	IfErrors end

	StrLen $0 $R0             ; $0 = Start position of word (11)
	StrLen $1 ':\lo'          ; $1 = Word length (4)
	; StrCpy $R0 $R1 $1 $0    ; $R0 = :\lo

	end:
SectionEnd

Example (With errorlevel output):

Section
	${WordFind} "[string]" "[delimiter]" "E[options]" $R0

	IfErrors 0 end
	StrCmp $R0 1 0 +2       ; errorlevel 1?
	MessageBox MB_OK 'delimiter not found' IDOK end
	StrCmp $R0 2 0 +2       ; errorlevel 2?
	MessageBox MB_OK 'no such word number' IDOK end
	StrCmp $R0 3 0 +2       ; errorlevel 3?
	MessageBox MB_OK 'syntax error'

	end:
SectionEnd

Example (Without errorlevel output):

Section
	${WordFind} "C:\io.sys C:\logo.sys" "_" "+1" $R0

	; $R0="C:\io.sys C:\logo.sys" (error: delimiter "_" not found)
SectionEnd

Example (If found):

Section
	${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "E+1{" $R0

	IfErrors notfound found
	found:
	MessageBox MB_OK 'Found' IDOK end
	notfound:
	MessageBox MB_OK 'Not found'

	end:
SectionEnd

Example (If found 2):

Section
	${WordFind} "C:\io.sys C:\logo.sys" ":\lo" "+1{" $R0

	StrCmp $R0 "C:\io.sys C:\logo.sys" notfound found        ; error?
	found:
	MessageBox MB_OK 'Found' IDOK end
	notfound:
	MessageBox MB_OK 'Not found'

	end:
SectionEnd

Example (To accept one word in string if delimiter not found):

Section
	StrCpy $0 'OneWord'
	StrCpy $1 1

	loop:
	${WordFind} "$0" " " "E+$1" $R0
	IfErrors 0 code
	StrCmp $1$R0 11 0 error
	StrCpy $R0 $0
	goto end

	code:
	; ...
	IntOp $1 $1 + 1
	goto loop

	error:
	StrCpy $1 ''
	StrCpy $R0 ''

	end:
	; $R0="OneWord"
SectionEnd

E.3.3 WordFindS

E.3.4 WordFind2X

  • Find word between two delimiters.
Strings:
"[delimiter1][word+1][delimiter2][delimiter1][word+2][delimiter2]..."
"[text][delimiter1][text][delimiter1][word+1][delimiter2][text]..."
"...[delimiter1][word-2][delimiter2][delimiter1][word-1][delimiter2]"
"...[text][delimiter1][text][delimiter1][word-1][delimiter2][text]"

Syntax:

${WordFind2X} "[string]" "[delimiter1]" "[delimiter2]" "[E][options]" $var
"[string]"         ;[string]
                   ;  input string
"[delimiter1]"     ;[delimiter1]
                   ;  first delimiter
"[delimiter2]"     ;[delimiter2]
                   ;  second delimiter
"[E][options]"     ;[options]
                   ;  +number   : word number from start
                   ;  -number   : word number from end
                   ;  +number}} : word number from start all space
                   ;              after this word to output
                   ;  +number{{ : word number from end all space
                   ;              before this word to output
                   ;  +number{} : word number from start
                   ;              all space before and after
                   ;              this word (word exclude)
                   ;  +number*} : word number from start
                   ;              all space after this
                   ;              word to output with word
                   ;  +number{* : word number from start
                   ;              all space before this
                   ;              word to output with word
                   ;  #         : sum of words to output
                   ;  /word     : number of word to output
                   ;
                   ;[E]
                   ;  with errorlevel output
                   ;  IfErrors:
                   ;     $var=1  no words found
                   ;     $var=2  no such word number
                   ;     $var=3  syntax error (Use: +1,-1,#)
                   ;[]
                   ;  no errorlevel output (default)
                   ;  If some errors found then (result=input string)
                   ;
$var               ;output (result)

Example (1):

Section
	${WordFind2X} "[C:\io.sys];[C:\logo.sys];[C:\WINDOWS]" "[C:\" "];" "+2" $R0
	; $R0="logo.sys"
SectionEnd

Example (2):

Section
	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1" $R0
	; $R0="logo"
SectionEnd

Example (3):

Section
	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{{" $R0
	; $R0="C:\WINDOWS C:\io.sys C:"
SectionEnd

Example (4):

Section
	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{}" $R0
	; $R0="C:\WINDOWS C:\io.sys C:sys"
SectionEnd

Example (5):

Section
	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "-1{*" $R0
	; $R0="C:\WINDOWS C:\io.sys C:\logo."
SectionEnd

Example (6):

Section
	${WordFind2X} "C:\WINDOWS C:\io.sys C:\logo.sys" "\" "." "/logo" $R0
	; $R0="2"
SectionEnd

Example (With errorlevel output):

Section
	${WordFind2X} "[io.sys];[C:\logo.sys]" "\" "];" "E+1" $R0
	; $R0="1" ("\...];" not found)

	IfErrors 0 noerrors
	MessageBox MB_OK 'Errorlevel=$R0' IDOK end

	noerrors:
	MessageBox MB_OK 'No errors'

	end:
SectionEnd

E.3.5 WordFind2XS

E.3.6 WordFind3X

  • Find a word that contains a string, between two delimiters.

Syntax:

${WordFind3X} "[string]" "[delimiter1]" "[center]" "[delimiter2]" "[E][options]" $var
"[string]"         ;[string]
                   ;  input string
"[delimiter1]"     ;[delimiter1]
                   ;  first delimiter
"[center]"         ;[center]
                   ;  center string
"[delimiter2]"     ;[delimiter2]
                   ;  second delimiter
"[E][options]"     ;[options]
                   ;  +number   : word number from start
                   ;  -number   : word number from end
                   ;  +number}} : word number from start all space
                   ;              after this word to output
                   ;  +number{{ : word number from end all space
                   ;              before this word to output
                   ;  +number{} : word number from start
                   ;              all space before and after
                   ;              this word (word exclude)
                   ;  +number*} : word number from start
                   ;              all space after this
                   ;              word to output with word
                   ;  +number{* : word number from start
                   ;              all space before this
                   ;              word to output with word
                   ;  #         : sum of words to output
                   ;  /word     : number of word to output
                   ;
                   ;[E]
                   ;  with errorlevel output
                   ;  IfErrors:
                   ;     $var=1  no words found
                   ;     $var=2  no such word number
                   ;     $var=3  syntax error (Use: +1,-1,#)
                   ;[]
                   ;  no errorlevel output (default)
                   ;  If some errors found then (result=input string)
                   ;
$var               ;output (result)

Example (1):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "+1" $R0
	; $R0="1.AAB"
SectionEnd

Example (2):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1" $R0
	; $R0="2.BAA"
SectionEnd

Example (3):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{{" $R0
	; $R0="[1.AAB];"
SectionEnd

Example (4):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{}" $R0
	; $R0="[1.AAB];[3.BBB];"
SectionEnd

Example (5):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "-1{*" $R0
	; $R0="[1.AAB];[2.BAA];"
SectionEnd

Example (6):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "AA" "];" "/2.BAA" $R0
	; $R0="2"
SectionEnd

Example (With errorlevel output):

Section
	${WordFind3X} "[1.AAB];[2.BAA];[3.BBB];" "[" "XX" "];" "E+1" $R0
	; $R0="1" ("[...XX...];" not found)

	IfErrors 0 noerrors
	MessageBox MB_OK 'Errorlevel=$R0' IDOK end

	noerrors:
	MessageBox MB_OK 'No errors'

	end:
SectionEnd

E.3.7 WordFind3XS

E.3.8 WordReplace

  • Replace or delete word from string.

Syntax:

${WordReplace} "[string]" "[word1]" "[word2]" "[E][options]" $var
"[string]"         ;[string]
                   ;  input string
"[word1]"          ;[word1]
                   ;  word to replace or delete
"[word2]"          ;[word2]
                   ;  replace with (if empty delete)
"[E][options]"     ;[options]
                   ;  +number  : word number from start
                   ;  -number  : word number from end
                   ;  +number* : word number from start multiple-replace
                   ;  -number* : word number from end multiple-replace
                   ;  +        : replace all results
                   ;  +*       : multiple-replace all results
                   ;  {        : if exists replace all delimiters
                   ;               from left edge
                   ;  }        : if exists replace all delimiters
                   ;               from right edge
                   ;  {}       : if exists replace all delimiters
                   ;               from edges
                   ;  {*       : if exists multiple-replace all
                   ;               delimiters from left edge
                   ;  }*       : if exists multiple-replace all
                   ;               delimiters from right edge
                   ;  {}*      : if exists multiple-replace all
                   ;               delimiters from edges
                   ;
                   ;[E]
                   ;  with errorlevel output
                   ;  IfErrors:
                   ;     $var=1  word to replace not found
                   ;     $var=2  no such word number
                   ;     $var=3  syntax error (Use: +1,-1,+1*,-1*,+,+*,{},{}*)
                   ;[]
                   ;  no errorlevel output (default)
                   ;  If some errors found then (result=input string)
                   ;
$var               ;output (result)

Example (replace):

Section
	${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "bmp" "+2" $R0
	; $R0="C:\io.sys C:\logo.bmp C:\WINDOWS"
SectionEnd

Example (delete):

Section
	${WordReplace} "C:\io.sys C:\logo.sys C:\WINDOWS" "SYS" "" "+" $R0
	; $R0="C:\io. C:\logo. C:\WINDOWS"
SectionEnd

Example (multiple-replace 1):

Section
	${WordReplace} "C:\io.sys      C:\logo.sys   C:\WINDOWS" " " " " "+1*" $R0
	; +1* or +2* or +3* or +4* or +5* or +6*
	; $R0="C:\io.sys C:\logo.sys   C:\WINDOWS"
SectionEnd

Example (multiple-replace 2):

Section
	${WordReplace} "C:\io.sys C:\logo.sysSYSsys C:\WINDOWS" "sys" "bmp" "+*" $R0
	; $R0="C:\io.bmp C:\logo.bmp C:\WINDOWS"
SectionEnd

Example (multiple-replace 3):

Section
	${WordReplace} "sysSYSsysC:\io.sys C:\logo.sys C:\WINDOWSsysSYSsys" "sys" "|" "{}*" $R0
	; $R0="|C:\io.sys C:\logo.sys C:\WINDOWS|"
SectionEnd

Example (With errorlevel output):

Section
	${WordReplace} "C:\io.sys C:\logo.sys" "sys" "bmp" "E+3" $R0
	; $R0="2" (no such word number "+3")

	IfErrors 0 noerrors
	MessageBox MB_OK 'Errorlevel=$R0' IDOK end

	noerrors:
	MessageBox MB_OK 'No errors'

	end:
SectionEnd

E.3.9 WordReplaceS

E.3.10 WordAdd

  • Add words to string1 from string2 if not exist or delete words if exist.

Syntax:

${WordAdd} "[string1]" "[delimiter]" "[E][options]" $var
"[string1]"          ;[string1]
                     ;  string for addition or removing
"[delimiter]"        ;[delimiter]
                     ;  one or several symbols
"[E][options]"       ;[options]
                     ;  +string2 : words to add
                     ;  -string2 : words to delete
                     ;
                     ;[E]
                     ;  with errorlevel output
                     ;  IfErrors:
                     ;     $var=1  delimiter is empty
                     ;     $var=3  syntax error (use: +text,-text)
                     ;[]
                     ;  no errorlevel output (default)
                     ;  If some errors found then (result=input string)
                     ;
$var                 ;output (result)

Example (add):

Section
	${WordAdd} "C:\io.sys C:\WINDOWS" " " "+C:\WINDOWS C:\config.sys" $R0
	; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd

Example (delete):

Section
	${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
	; $R0="C:\logo.sys"
SectionEnd

Example (add to one):

Section
	${WordAdd} "C:\io.sys" " " "+C:\WINDOWS C:\config.sys C:\IO.SYS" $R0
	; $R0="C:\io.sys C:\WINDOWS C:\config.sys"
SectionEnd

Example (delete one):

Section
	${WordAdd} "C:\io.sys C:\logo.sys C:\WINDOWS" " " "-C:\WINDOWS" $R0
	; $R0="C:\io.sys C:\logo.sys"
SectionEnd

Example (No new words found):

Section
	${WordAdd} "C:\io.sys C:\logo.sys" " " "+C:\logo.sys" $R0
	StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
	MessageBox MB_OK "No new words found to add"
SectionEnd

Example (No words deleted):

Section
	${WordAdd} "C:\io.sys C:\logo.sys" " " "-C:\config.sys" $R0
	StrCmp $R0 "C:\io.sys C:\logo.sys" 0 +2
	MessageBox MB_OK "No words found to delete"
SectionEnd

Example (With errorlevel output):

Section
	${WordAdd} "C:\io.sys C:\logo.sys" "" "E-C:\logo.sys" $R0
	; $R0="1" (delimiter is empty "")

	IfErrors 0 noerrors
	MessageBox MB_OK 'Errorlevel=$R0' IDOK end

	noerrors:
	MessageBox MB_OK 'No errors'

	end:
SectionEnd

E.3.11 WordAddS

  • Same as WordAdd, but case sensitive.

E.3.12 WordInsert

  • Insert word in string.

Syntax:

${WordInsert} "[string]" "[delimiter]" "[word]" "[E][options]" $var
"[string]"          ;[string]
                    ;  input string
"[delimiter]"       ;[delimiter]
                    ;  one or several symbols
"[word]"            ;[word]
                    ;  word to insert
"[E][options]"      ;[options]
                    ;  +number  : word number from start
                    ;  -number  : word number from end
                    ;
                    ;[E]
                    ;  with errorlevel output
                    ;  IfErrors:
                    ;     $var=1  delimiter is empty
                    ;     $var=2  wrong word number
                    ;     $var=3  syntax error (Use: +1,-1)
                    ;[]
                    ;  no errorlevel output (default)
                    ;  If some errors found then (result=input string)
                    ;
$var                ;output (result)

Example (1):

Section
	${WordInsert} "C:\io.sys C:\WINDOWS" " " "C:\logo.sys" "-2" $R0
	; $R0="C:\io.sys C:\logo.sys C:\WINDOWS"
SectionEnd

Example (2):

Section
	${WordInsert} "C:\io.sys" " " "C:\WINDOWS" "+2" $R0
	; $R0="C:\io.sys C:\WINDOWS"
SectionEnd

Example (3):

Section
	${WordInsert} "" " " "C:\WINDOWS" "+1" $R0
	; $R0="C:\WINDOWS "
SectionEnd

Example (With errorlevel output):

Section
	${WordInsert} "C:\io.sys C:\logo.sys" " " "C:\logo.sys" "E+4" $R0
	; $R0="2" (wrong word number "+4")

	IfErrors 0 noerrors
	MessageBox MB_OK 'Errorlevel=$R0' IDOK end

	noerrors:
	MessageBox MB_OK 'No errors'

	end:
SectionEnd

E.3.13 WordInsertS

E.3.14 StrFilter

  • Convert string to uppercase or lowercase.
  • Set symbol filter.

Syntax:

${StrFilter} "[string]" "[options]" "[symbols1]" "[symbols2]" $var
"[string]"       ;[string]
                 ;  input string
                 ;
"[options]"      ;[+|-][1|2|3|12|23|31][eng|rus]
                 ;  +   : convert string to uppercase
                 ;  -   : convert string to lowercase
                 ;  1   : only Digits
                 ;  2   : only Letters
                 ;  3   : only Special
                 ;  12  : only Digits  + Letters
                 ;  23  : only Letters + Special
                 ;  31  : only Special + Digits
                 ;  eng : English symbols (default)
                 ;  rus : Russian symbols
                 ;
"[symbols1]"     ;[symbols1]
                 ;  symbols include (not changeable)
                 ;
"[symbols2]"     ;[symbols2]
                 ;  symbols exclude
                 ;
$var             ;output (result)

Note:
- Error flag if syntax error
- Same symbol to include & to exclude = to exclude

Example (UpperCase):

Section
	${StrFilter} "123abc 456DEF 7890|%#" "+" "" "" $R0
	; $R0="123ABC 456DEF 7890|%#"
SectionEnd

Example (LowerCase):

Section
	${StrFilter} "123abc 456DEF 7890|%#" "-" "ef" "" $R0
	; $R0="123abc 456dEF 7890|%#"
SectionEnd

Example (Filter1):

Section
	${StrFilter} "123abc 456DEF 7890|%#" "2" "|%" "" $R0
	; $R0="abcDEF|%"       ;only Letters + |%
SectionEnd

Example (Filter2):

Section
	${StrFilter} "123abc 456DEF 7890|%#" "13" "af" "4590" $R0
	; $R0="123a 6F 78|%#"  ;only Digits + Special + af - 4590
SectionEnd

Example (Filter3):

Section
	${StrFilter} "123abc 456DEF 7890|%#" "+12" "b" "def" $R0
	; $R0="123AbC4567890"  ;only Digits + Letters + b - def
SectionEnd

Example (Filter4):

Section
	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "+12rus" "ä" "ãå" $R0
	; $R0="123ÀÁÂ456ä7890"  ;only Digits + Letters + ä - ãå
SectionEnd

Example (English + Russian Letters):

Section
	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2rus" "" "" $R0
	; $R0="ÀÁÂãäå"        ;only Russian Letters
	${StrFilter} "123abcÀÁÂ 456DEFãäå 7890|%#" "2" "$R0" "" $R0
	; $R0="abcÀÁÂDEFãäå"  ;only English + Russian Letters
SectionEnd

Example (Word Capitalize):

Section
	Push "_01-PERPETUOUS_DREAMER__-__THE_SOUND_OF_GOODBYE_(ORIG._MIX).MP3_"
	Call Capitalize
	Pop $R0
	; $R0="_01-Perpetuous_Dreamer__-__The_Sound_Of_Goodbye_(Orig._Mix).mp3_"

	${WordReplace} "$R0" "_" " " "+*" $R0
	; $R0=" 01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3 "

	${WordReplace} "$R0" " " "" "{}" $R0
	; $R0="01-Perpetuous Dreamer - The Sound Of Goodbye (Orig. Mix).mp3"
SectionEnd

Function Capitalize
	Exch $R0
	Push $0
	Push $1
	Push $2

	${StrFilter} '$R0' '-eng' '' '' $R0
	${StrFilter} '$R0' '-rus' '' '' $R0

	StrCpy $0 0

	loop:
	IntOp $0 $0 + 1
	StrCpy $1 $R0 1 $0
	StrCmp $1 '' end
	StrCmp $1 ' ' +5
	StrCmp $1 '_' +4
	StrCmp $1 '-' +3
	StrCmp $1 '(' +2
	StrCmp $1 '[' 0 loop
	IntOp $0 $0 + 1
	StrCpy $1 $R0 1 $0
	StrCmp $1 '' end

	${StrFilter} '$1' '+eng' '' '' $1
	${StrFilter} '$1' '+rus' '' '' $1

	StrCpy $2 $R0 $0
	IntOp $0 $0 + 1
	StrCpy $R0 $R0 '' $0
	IntOp $0 $0 - 2
	StrCpy $R0 '$2$1$R0'
	goto loop

	end:
	Pop $2
	Pop $1
	Pop $0
	Exch $R0
FunctionEnd

E.3.15 StrFilterS

E.3.16 VersionCompare

  • Compare version numbers.

Syntax:

${VersionCompare} "[Version1]" "[Version2]" $var
"[Version1]"        ; First version
"[Version2]"        ; Second version
$var                ; Result:
                    ;    $var=0  Versions are equal
                    ;    $var=1  Version1 is newer
                    ;    $var=2  Version2 is newer

Example:

Section
	${VersionCompare} "1.1.1.9" "1.1.1.01" $R0
	; $R0="1"
SectionEnd

E.3.17 VersionConvert

  • Convert version in the numerical format which can be compared.

Syntax:

${VersionConvert} "[Version]" "[CharList]" $var
"[Version]"         ; Version
                    ;
"[CharList]"        ; List of characters, which will be replaced by numbers
                    ; "abcdefghijklmnopqrstuvwxyz" (default)
                    ;
$var                ; Result: converted version

Note:
- Converted letters are separated with dot
- If character is non-digit and not in list then it will be converted to dot

Example1:

Section
	${VersionConvert} "9.0a" "" $R0
	; $R0="9.0.01"

	${VersionConvert} "9.0c" "" $R1
	; $R1="9.0.03"

	${VersionCompare} "$R0" "$R1" $R2
	; $R2="2"   version2 is newer
SectionEnd

Example2:

Section
	${VersionConvert} "0.15c-9m" "" $R0
	; $R0="0.15.03.9.13"

	${VersionConvert} "0.15c-1n" "" $R1
	; $R1="0.15.03.1.14"

	${VersionCompare} "$R0" "$R1" $R2
	; $R2="1"   version1 is newer
SectionEnd

Example3:

Section
	${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
	; $R0="0.15.0327"

	${VersionConvert} "0.15c" "abcdefghijklmnopqrstuvwxyz+" $R1
	; $R1="0.15.03"

	${VersionCompare} "$R0" "$R1" $R2
	; $R2="1"   version1 is newer
SectionEnd

Previous | Contents | Next