Archive: Error in WordFind ?


Error in WordFind ?
Hello all,

i have a strange problem occuring here, i use the following code to count how many times a String appears in a another String (seperated by ,). But for some reason its counted wrong BCDE are definitely only contained once!


Var /Global LicenseFeatures
Var /Global TESTA
Var /Global TESTB
Var /Global TESTC
Var /Global TESTD
Var /Global TESTE
Var /Global TESTF

Section TEST

StrCpy $LicenseFeatures "A,B,C,D,E,F"

${WordFind} "$LicenseFeatures" "A" "#" $TESTA
${WordFind} "$LicenseFeatures" "B" "#" $TESTB
${WordFind} "$LicenseFeatures" "C" "#" $TESTC
${WordFind} "$LicenseFeatures" "D" "#" $TESTD
${WordFind} "$LicenseFeatures" "E" "#" $TESTE
${WordFind} "$LicenseFeatures" "F" "#" $TESTF

MessageBox MB_OK "LicenseFeatures: $LicenseFeatures $\r$\n \
A: $TESTA $\r$\n \
B: $TESTB $\r$\n \
C: $TESTC $\r$\n \
D: $TESTD $\r$\n \
E: $TESTE $\r$\n \
F: $TESTF $\r$\n"
SectionEnd



the result is:

LicenseFeatures: A,B,C,D,E,F

A: 1

B: 2

C: 2

D: 2

E: 2

F: 1

Any Ideas?

When you use the "#" as the option for ${WordFind} it returns the sum of the words. What you want is "*" to return the count of delimiters.

Var /Global LicenseFeatures
Var /Global TESTA
Var /Global TESTB
Var /Global TESTC
Var /Global TESTD
Var /Global TESTE
Var /Global TESTF

Section TEST

StrCpy $LicenseFeatures "A,B,C,D,E,F"

${WordFind} "$LicenseFeatures" "A" "*" $TESTA
${WordFind} "$LicenseFeatures" "B" "*" $TESTB
${WordFind} "$LicenseFeatures" "C" "*" $TESTC
${WordFind} "$LicenseFeatures" "D" "*" $TESTD
${WordFind} "$LicenseFeatures" "E" "*" $TESTE
${WordFind} "$LicenseFeatures" "F" "*" $TESTF

MessageBox MB_OK "LicenseFeatures: $LicenseFeatures $\r$\n \
A: $TESTA $\r$\n \
B: $TESTB $\r$\n \
C: $TESTC $\r$\n \
D: $TESTD $\r$\n \
E: $TESTE $\r$\n \
F: $TESTF $\r$\n"
SectionEnd

Thanks that works, but then what is the sum of the words?


Sum of words is the count of words parsed between around the delimiter. Since you only have one delimiter in a string it will always show 1 or 2.

Typically you will use it to get the count of items.

Example:

${WordFind} "A,B,C,D,E,F" "," "*" $0
; $0 = 6

Thanks.