Archive: New Function


New Function
Usage:
Push "My name is Afrow UK, and I love NSIS"
Push "4"
Call GetStringPart
Pop "$R0"
$R0 should now be "My name is Afrow UK," but it's not working.
I definatly had this script working before, and now it does not work at all.


Function GetStringPart
Pop $R4
Exch $R0
Push $R1
Push $R2
Push $R3
StrCpy $R1 -1
StrCpy $R3 0
loop:
StrCpy $R2 $R0 1 $R1
StrCmp $R3 $R4 exit2
StrCmp $R2 "" exit2
StrCmp $R2 " " exit ; Change " " to "\" if ur inputting dir path str
IntOp $R1 $R1 - 1
Goto loop
exit:
StrCpy $R0 $R0 $R1
IntOp $R3 $R3 + 1
Goto loop
exit2:
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd


Basically, it will clear the string from the start up to the space specified.
Thats where the Push "4" comes in. It should reomve all of the string from the end up to the 4th space.

Can anyone see whats wrong with it?

-Stuart

I completely re-wrote the script, and got a far better script than from before.
Instead, it just gets the fisrt part of a string before the first space (or character of your choice)

Usage:
Push "My name is Afrow UK, and I love NSIS"
Call GetFirstStrPart
Pop $R0

$R0 is now "My"


Function GetFirstStrPart
Exch $R0
Push $R1
Push $R2
Push $R3
StrLen $R3 $R0
IntOp $R3 $R3 + 1
loop:
IntOp $R3 $R3 - 1
StrCpy $R2 $R0 1 -$R3
DetailPrint $R2
StrCmp $R2 "" exit
StrCmp $R2 " " exit ; Change " " to "\" if ur inputting dir path str
Goto loop
exit:
StrCpy $R0 $R0 -$R3
IntOp $R1 $R1 + 1
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd


-Stuart

But for what you want this? Because already have the function "Advanced Search in String". Seach for " " in "My name is Afrow UK, and I love NSIS", use the option to show the str before the " ", and the option to not show the " ", the result will be the same (My).

[EDIT]And you can get any part of the str with the loops option:

Example: 0 loops will return "My"
1 loop will return "My name"
2 loops will return "My name is"
3 loops will return "My name is Afrow"
...


I have a suggestion for you, how about the user push the caracter or str to be searched? (like StrStr)


The reason I'm not going to use Advanced Str Search, is because my program reads from a 500kb log file and searches each line one by one, using StrStr to search through that line, then this script then GetFileName and so on. It already takes a very long time to parse the whole log.

Using Advanced Str Search would increase the time noticibly, where it has to be called over 1000 times!

-Stuart


But you will use your GetFirstStrPart for every line of the log file?