Archive: Instr-Function in NSIS?


Instr-Function in NSIS?
Hi,
I have some Basic code and wonder, how to port it to NSIS:

dim x as string
dim y as integer
x = "123456"
y = instr(1,x,"23")

so y is the position of the signs 23, but how to realize this in NSIS?

Thanks!


Anyone? I am under high time pressure, any tips are welcome!


Hi, found out myself:

!include "StrFunc.nsh"
${StrLoc}
...
${StrLoc} $TempPath "This is just an example" "just" "<"
...


btw: anyone has an idea, how to find the second appearence of a string in another string? for example:
string = "Test Test Test"
searchString = "Test"
should say position is 6, because the second string starts at this position.


${StrStrAdv} should do the trick. See the ${NSISDIR}\Docs\StrFunc for details.

You might also take a look at the Word Functions in Appendix E of the NSIS help files for other string manipulation functions.


Hi, thanks a lot for this help.
Now I have a string to a path:
"C:\Program Files\Program
but the first char is a ", I want to remove this, I thought of either using a Replace or Trim function. My replace function:
${StrRep} $tempPath $tempPath """ ""
but it gives an error, since I have " as a value of the function, any idea?


StrLoc Help needed
Hi ,

I'm using NSIS,
When i call StrLoc i'm getting error

Error: resolving install function "StrLoc" in function "InstallJavaPageLeave"
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process

I'm calling StrLoc like below:
-------------------------------

!include "LogicLib.nsh"
!include "StrFunc.nsh"

Push "This is just an example"
Push "just"
Push "<"
Call StrLoc
Pop $0



Thanks in advance,
Srinivas N


You should review the StrFunc documentation, e.g.

!include "StrFunc.nsh"
${StrLoc}

........

section
${StrLoc} $0 "This is just an example" "just" "<"

.......


Hi,
and for example, how could I use a " sign in a string:

${StrRep} $Path "12345 " " """ "6789"

perhaps with the ASCII-code?

Any idea is welcome!!


Try out this...

'Some string with "doublequote"'

${StrRep} $Path "12345 " ' ""' "6789"

And By the way i wanted to ask you how ur able to use
"StrLoc" can u upload ur required .nsh function or sample code ur using, i saw that ur also have some problem with StrLoc.

And my requirement is like , i'm setting up the "path" environment variable after the java installation.

it looks like this PATH="C:\JAVA\BIN\";

And i want to check if that PATH is already exists in that evironment variable PATH,If not then only i want to set the path,Other wise PATH will be appended multiple times like
PATH="C:\JAVA\BIN;C:\JAVA\BIN"; which is almost wrong looks irregular.At this point of time i don't want the code for How to read and write environment variable etc. i need only how to check the occurence of the string after i get the path in some local variable let us say $R4.





Thanks in advance,
Srinivas N


I use the following macros and functions to add (or remove) paths to the PATH environment variable:

Section -PathVar
# Environment Path variable
Push 1 ; prefix
Push "C:\Ipls\dlls"
Call SetPathVar

Push 2 ; append
Push "C:\Ipls\utilities;C:\ipls\utilities\pkzip;"
Call SetPathVar
SectionEnd

Section Uninstall
...
# cleanup the Environment Path variable
Push 0 ; 0 = remove
Push "C:\Ipls\dlls;C:\Ipls\utilities;C:\ipls\utilities\pkzip"
Call Un.SetPathVar
SectionEnd

...
!macro DualUseFunctions_ un_
function ${un_}SetPathVar
Exch $0 ; new string
Exch
Exch $1 ; append = 2, prefix = 1, remove = 0
Push $R0 ; saved working registers

ReadRegStr $R0 HKLM "${REG_ENVIRONMENT}" "Path"

${Select} $1
${Case} 0
${${un_}WordAdd} "$R0" ";" "-$0" $R0
${Case} 1
${${un_}WordAdd} "$0" ";" "+$R0" $R0
${Case} 2
${${un_}WordAdd} "$R0" ";" "+$0" $R0
${EndSelect}

WriteRegExpandStr HKLM "${REG_ENVIRONMENT}" "Path" "$R0"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r2'

Pop $R0 ; restore registers
Pop $1
Pop $0
functionEnd
!macroend
!insertmacro DualUseFunctions_ ""
!insertmacro DualUseFunctions_ "un."

My uninstaller calls ${un.SetPathVar} to remove what I've added.

${WordAdd} is in the WordFunc.nsh header and requires these lines near the top of your script
!include "LogicLib.nsh"
!include "WordFunc.nsh"
!insertmacro WordAdd
!define REG_ENVIRONMENT "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"


Don