Page 1 of 1

Fields of Joy... but Start of Line? (='.'=)

Posted: Thu May 30, 2013 4:33 pm
by Mariasole
Ciao a tutti!!!!

I am continuing to study the basics of LiveCode! :) (but not the English language!... sorry)
I'm stuck on another problem from beginner ... :(
I have a list of strings in a field (fString) to be compared (exactly!, case sensitive...) with a list of another field (fWordOk).
A textbook problem, right? For a newbie... ;)

Here is the example...


field fString content

aaaaaaa
bbbbbbb
Aaaaaaa
bbbbbbB
aaaA
lkjlkjlkjlk
Cat
aaa


field fWordOk content

aaaaaaa
bbbbbbb
Aaaaaaa
bbbbbbB
aaaa

Here is the simple ;) code:

Code: Select all

on mouseUp
            
repeat for each line tLine in field "fString"

   set the caseSensitive to true
   set the wholeMatches to true
   
answer tLine

                 IF (tLine & return) is not in field "fWordOk" THEN


                     answer "the word |" & tLine & "| does not exist !!!"
                     
                  ELSE

                                          answer "the word |" & tLine & "| exist !!!"
                     
                                       end if
                      
                     
                     end repeat
                     
end mouseUp



And here is the result!:


aaaaaaa -----------> exist !!! :)
bbbbbbb -----------> exist !!! :)
Aaaaaaa -----------> exist !!! :)
bbbbbbB -----------> exist !!! :)
aaaA -----------> does not exist !!! :)
lkjlkjlkjlk -----------> does not exist !!! :)
Cat -----------> does not exist !!! :)

but...

aaa -----------> exist !!! :( :( :( (=*.*=)

My "elegant" :) solution in PigCode is:

Code: Select all


 IF (STARTOFLINE & tLine & return) is not in field "fWordOk" THEN...

But... what is the translation of the STARTOFLINE command from PigCode to LiveCode? :)


Thanks again to everyone!!
Grazie a tutti e baci!!!!!!

Mariasole

(='.'=)

Re: Fields of Joy... but Start of Line? (='.'=)

Posted: Thu May 30, 2013 9:00 pm
by SparkOut
Ciao Mariasole,
Using a slightly different approach, but again a very useful demonstration of the versatile chunking and text handling capabilities of LiveCode:

Code: Select all

repeat for each line tLine in field "fString"
      set the caseSensitive to true
      set the wholeMatches to true
      answer tLine
      if tLine is not among the lines of field "fWordOk" then
         answer "the word |" & tLine & "| does not exist !!!"
      else
         answer "the word |" & tLine & "| exist !!!"
      end if
   end repeat
How does that work for you?

Re: Fields of Joy... but Start of Line? (='.'=)

Posted: Mon Jun 03, 2013 3:32 pm
by Mariasole
Thanks SparkOut!
I tried your solution! And it works! Thank you for teaching me again the simplicity of LiveCode! :)
A tagline of LiveCode brand might just be "sic et simpliciter"!!! ;)

Grazie SparkOut!!!

Baci!!!

Mariasole (='.'=)