|
|
|
|
#1 |
|
Junior Member
Join Date: Oct 2015
Posts: 8
|
Can you search for multiple strcontains?
Me again:
Can you look for multiple strcontains in a file? I've tried a couple of variations, what I want to do is below, but it only ever seems to find the first ${strcontains}, and then skips over the rest. The file itself has multiple lines. Some of the lines will have the text I am searching for, and some won't. A typical file will look like this: STAGES.TXT Stage1true Stage2true pmp123456 EXP000479 cusMarkatSADiE Stage3true EOF iffileexists "$Temp\stages.txt" openfile nofile openfile: Fileopen $9 "$Temp\Stages.txt" r ${ForEach} $i 1 $R0 + 1 Fileread $9 $R4 10 pop $R4 ${strcontains} $serial "EXP" $R4 STRCMP $serial "" notfound strcpy $serial $R4 messagebox mb_ok " Serial number is: $serial" ${strcontains} $order "pmp" $R4 STRCMP $order "" notfound strcpy $order $R4 messagebox mb_ok " Order number is: $order" ${strcontains} $customer "cus" $R4 STRCMP $customer "" notfound strcpy $customer $R4 messagebox mb_ok " Customer is: $customer" goto done notfound: ; I never found nothin' done: ${Next} What am I missing? |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
And strcontains is a macro you wrote? found somewhere? from the wiki?
If the line always starts with the part of the string you are looking for it is better to just use StrCpy with the maxlen parameter to copy the first 3 characters and then StrCmp that... IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Oct 2015
Posts: 8
|
Oh Lord, I can barely write my own name, let alone write a macro... It's one I found ages ago http://nsis.sourceforge.net/StrContains
Yes you're right Anders, I wasn't thinking. I already have the strcontains function loaded to check for the occurance of a vendor Id (To see if a particular USB device is plugged in), so I figured I'd just reuse the function, but it only seems to find the first instance... i.e. it finds the serial number, and ignors the rest. I'll try it another way. Thanks |
|
|
|
|
|
#4 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
|
pop $R4 in your script does not look right to me. Passing 10 as the maxlen also seems strange unless STAGES.TXT does not contain any newlines at all but then "cusMarkatSADiE" would be too long?
If each entry is on their own line I would just do: PHP Code:
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Oct 2015
Posts: 8
|
Thanks Anders, that makes sense. I should have increased the maxlen. It was initially there when I was on;y looking for stagextrue.
I'll have another go at this when I get back from holiday Yay Holiday.Thanks for your help. Mark |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|