- New lines "`r`n" can be stored in the "Keys"
(Extra Files) ListView Control (TickCount Speed Test) \ Edit Controls (New Lines "`r`n" test)
VarWrite \ VarRead (Functions):
Code: Select all
VarWrite(Key := "", Value := "") ;_____________ VarWrite (Function) __________________
{
Static Var ;"Static" variables are always implicitly "local", but differ from "locals" variables because their values are remembered between calls.
if Key = ;if "Key" is blank
{
if Value = GetVar
return, Var
Var = %Value%
return
}
Value := RegExReplace(Value, "#","##") ;replace any "#" to "##" (Ensures that no String\Character is enclosed by "##")
Value := RegExReplace(Value, "`r`n","#L#") ;replace any New Line "`r`n" to "#L#" (these replacements will be the only String\Character enclosed by "##")
If RegExMatch(Var, "m)^" Key "=""(.*)""" , Matched) ;"m)" Search for a line \ "^" that starts by \ "Key" the string choosed by user \ followed by =" string \ (.*)"" match any string until last " character is found in that line
{ ;All the match wil be stored in "Matched" variable \ the match inside first "( )" will be stored in "Matched1" \ the match inside second "( )" will be stored in "Matched2", and so on ...
if (Matched1 == Value) ;first " treats second " as literal character \ "= =" case sensitive (a is not A)
return ;return if the value to be rewritten is the same as the "key" value (Faster this way)
Value := RegExReplace(Value, "\$", "$$$$") ;replace any "$" to "$$" (necessary because "$" is a special character in RegExReplace 3rd parameter)
;"\" treats "$" as literal character - "$$$$" the first "$" treats the second "$" as literal character, so, "$$$$" = "$$" literal string in RegExReplace 3rd parameter
Var := RegExReplace(Var, "m)(^" Key "=).*", "$1""" Value """") ;[""], first " treats second " as literal character, so, """" means that there is a literal " character between two Special " characers
} ;"$1", in this case, it's a backreference to (^" Key "=) \ $2 would be a backreference to the second ( ) \ $3 for the 3rd ( ) \ and so on ...
else ;".*" match any string (the rest of the string left) of that line
Var = %Var%`r`n%Key%="%Value%" ;"value", the value specified by user
}
VarRead(Key := "", Variable := "") ;_______________ VarRead (Function) ________________
{
Static Var ;"Static" variables are always implicitly "local", but differ from "locals" variables because their values are remembered between calls.
if Key = ;if "Key" is blank
{
Var = %Variable%
return
}
RegExMatch(Var, "m)^" Key "=""(.*)""" , Matched) ;"m)" Search for a line \ "^" that starts by \ "Key" the string choosed by user \ followed by =" string
;(.*)"" match any string until last " character from that line is found
;All the match wil be stored in "Matched" variable
;the match inside first "( )" will be stored in "Matched1"
;the match inside second "( )" will be stored in "Matched2", and so on ...
;first " treats second " as literal character
Matched1 := RegExReplace(Matched1, "##(*SKIP)(*F)|#L#", "`r`n") ;replace any "#L#" to "`r`n" (any "##" will be skipped)
Matched1 := RegExReplace(Matched1, "##", "#") ;replace any "##" to "#" (necessary because "VarWrite( )" Function replaces any "#" to "##")
return, Matched1
}