Page 1 of 1

Strange results with "if string contains"

Posted: Tue Mar 09, 2010 12:13 pm
by heyvern
I have a list of strings separated by returns. In a custom function I loop through each line comparing a string to the lines which contain one word each.
Here is the value in my global variable that is giving me a false true value:

"scale>"

The string that is compared to this value that returns an incorrect "true" match is this:

"scale_compensation true"

If I try this with a direct string comparison it works correctly:

Code: Select all

If "scale_compensation true" contains "scale>" then
  put true into message
else
  put false into message
end if
The above returns false as expected.

But if the same match is done via a loop through a list of words then it returns a TRUE when it hits that "scale_compensation true" string value.
the global variable gTransforms contains:

Code: Select all

--Global gTransforms--
translation>
scale>
rotation_x>
rotation_y>
rotation_z>
flip_h>
flip_v>
shear>
I send the following line of another string:

"scale_compensation true"

to the function below:

Code: Select all

function ReversTransforms theText
  repeat for each line j in gTransforms
    if theText contains j then
       put true into returnVal
       exit repeat
     else
       put false into returnVal
     end if
  end repeat
  return returnVal
end ReversTransforms
For some reason the string containing "scale_compensation true" returns true by matching "scale>"

Re: Strange results with "if string contains"

Posted: Tue Mar 09, 2010 12:29 pm
by bangkok

Code: Select all

  repeat for each line j in gTransforms
    if theText contains j then
It should be :

Code: Select all

    if theText contains line j of gTransforms then
no ?

Re: Strange results with "if string contains"

Posted: Tue Mar 09, 2010 2:01 pm
by bn
Heyvern,
your code works for me as it is. Could it be that you have something in your global, trailing line with only a space for example, that returns the erroneous true?
regards
Bern

Re: Strange results with "if string contains"

Posted: Wed Mar 10, 2010 1:11 am
by heyvern
You are a genius! :)

That was it. I did a copy and paste for each line to insert the freaking words into my global variable and forgot to delete the "& return" on the last item!!!! Dang extra return. Odd though. I thought doing "for each line k" wouldn't have a return that matches but apparently it does.

Thanks dude!

Re: Strange results with "if string contains"

Posted: Wed Mar 10, 2010 11:39 am
by bn
hyvern,
heyvern wrote:You are a genius
That is plain wrong, I have tons of evidence to refute that :)

heyvern wrote: That was it. I did a copy and paste for each line to insert the freaking words into my global variable and forgot to delete the "& return" on the last item!!!! Dang extra return. Odd though. I thought doing "for each line k" wouldn't have a return that matches but apparently it does.!
Although a trailing return can do all sort of funny things it does not explain in my testing what happened. A simple trailing return was no problem.
There must have been a space also (or something else) that matched to your string.
regards
Bernd

Re: Strange results with "if string contains"

Posted: Wed Mar 10, 2010 8:30 pm
by heyvern
It could be there was something odd with my string that I "fixed" accidentally, but it was incorrect with the trailing return, and correct when I removed it. The source data is very "precise". No extra spaces, everything indented with tabs. However it is possible there are extra returns. I am at that stage of production where the code is a bit "messy". It all works but it isn't exactly... straight forward. I have started to consolidate and clean things up. I am VERY new with RR. Just started the second month of the demo. Most of my expertise is with lua so there is a bit of a learning curve. I think the hardest part of using RR is dealing with "extra" returns when splitting with delimiters. Splitting items seems to introduce unexpected returns depending on where the delimiter is. This is user error for sure. Sometimes my item delimiters are on their own separate line which causes an extra line.