xirisone
11th February 2008 09:04 UTC
WordFind can't count?
Hi,
I want to detect whether a substring is present in a string.
I try to count how often a substring occurs in a string using WordFind...
As long as the substring occurs at least once it works.
But if the the substring is not present at all I don't get '0' as expected (and needed!) but I get the string I searched in as result.
Any Ideas?
Sample:
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "*" $R0
detailprint "found 'sys' [$R0] times." // Ok, result = 2
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "xyz" "*" $R0
detailprint "found 'xyz' [$R0] times."
This fails, $R0 contains "C:\io.sys C:\logo.sys C:\WINDOWS"
xirisone
kichik
11th February 2008 20:32 UTC
As the documentation says, if you don't use E in the options, you get the input string back in case of errors.
If some errors found then (result=input string)
Use the E option and check for the error specifying zero delimiters or just compare the result to the input string.
xirisone
12th February 2008 17:56 UTC
@kichik
I'll check that out.
Still I have a problem of understanding... I'd say the result of '0' times found is a valid result and no error. The function should simply return '0'. The documentation even says the code I used is a sample for counting.
xirisone
kichik
12th February 2008 21:42 UTC
Where exactly does the documentation say that? I can't find it.
xirisone
13th February 2008 08:25 UTC
The documentation at 'E.3.2 WordFind' says:
Example (Sum of delimiters):
Section
${WordFind} "C:\io.sys C:\logo.sys C:\WINDOWS" "sys" "*" $R0
; $R0="2"
SectionEnd
My interpretation was, that I get the count how often the delimiter is found and '0' times found is a valid result (thought it worked without using the E parameter).
The problem itself is easy enough to solve, it's just for my understanding.
TIA,
xirisone