contains...with 2 Variables

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 7:02 am

Hi,

I am currently working with the Contains function and have run into an oddity that I cant seem to fix.

The issue is when I set the stringtofind as a variable I can never get a true result.
I can see looking in LC Variable watcher that the variable contains exaclty what it should (File1.pdf) but it just won't give a true result.

any idea's?

Like below

Code: Select all

if fld "Bob" contains tVariable then
--do something
But

If I manually assign the stringtofind it works fine??
Like below

Code: Select all

if fld "Bob" contains "File1.pdf" then
--do something

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 7:19 am

After experimenting some more I think it is because I replaced tab with empty in the Variable..
Inplace of replacing it how do I just delete all Tabs in a specific line of a fld?

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: contains...with 2 Variables

Post by dave_probertGA6e24 » Wed Jan 16, 2013 7:39 am

Hi,

Try this (in message box or wherever)):

Code: Select all

put "xxx a xxxx"&cr&"xxx a xxxx"&cr&"xxx a xxxx"&cr into tst

put "BEFORE:" & cr & tst & cr

put line 2 of tst into xxx
replace "a" with "DAVE" in xxx
put xxx into line 2 of tst

put "AFTER:" & cr & tst & cr

Just change the replace to:

Code: Select all

replace tab with empty in xxx
to get the effect you want.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 7:52 am

Thanks.

What I am actually doing in more detail is getting a list of files available in a specific folder on a FTP Server.
This lists is returned with eaps of junk that I have filtered out (rights, size, time etc) and is also TAB delimited so i just replaced the tab with empty..

But now the variable all looks correct it obviously is not becuase when I do a tVariable = "VisibleVariableContent" it returns a false..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 7:57 am

dave_probertGA6e24 wrote:Hi,

Try this (in message box or wherever)):

Code: Select all

put "xxx a xxxx"&cr&"xxx a xxxx"&cr&"xxx a xxxx"&cr into tst

put "BEFORE:" & cr & tst & cr

put line 2 of tst into xxx
replace "a" with "DAVE" in xxx
put xxx into line 2 of tst

put "AFTER:" & cr & tst & cr

Just change the replace to:

Code: Select all

replace tab with empty in xxx
to get the effect you want.

Cheers,
Dave
Im sorry but your top example doesn't really help at all?
Could you explain it a little further....

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 10:08 am

After spending plenty of time on this I seem to be getting nowhere :(

Is it possible that the file list I am retrieving from the FTP Server may be URLEncoded? (this is what is building the Variable mentioned in earlier posts)
The list it returns when I use the following handler has heaps of extra information that I simply filter out what as needed (replace with empty etc)

What is the best way to check if the list it returns is URLEncoded?

Code: Select all

put URL ("ftp://" & URLEncode(tUser) & ":" & URLEncode(tPass)  & "@" & gLocation & tFolder) into tFileList

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: contains...with 2 Variables

Post by shaosean » Wed Jan 16, 2013 10:53 am

FTP servers do not URLEncode the returned data.. Different FTP servers return the file listings formatted differently and the ones that I have tested all return the listings spaced out with spaces and not tabs..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 11:12 am

Here is an example of what I receive when I retrieve the file list
"01-16-13 10:17AM 142478 Test2.pdf"

Doing a replace space with empty on this result does nothing but replacing tab does
so I conclude it is TAB delimited..

Have done some further reading and see URL encoding shouldn't be an issue on FTP.
So, not sure where to from here.

I can view the Variable I create containing the filename in a messagebox and it appears perfect but just can't search against it and if I perform a
put Varibale = "TypedVariableContents" it always returns a false...

Is there a way I can check the Variable for any "hidden" elements/contents

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 11:39 am

Okay,

I have made an example Stack with example data loaded.
The test handler is in the Card script. If anyone can tell me why that evaluates false I would love to know why :x

Note- If you retype the contents of the flds (through the properties inspector etc) it will work but this isn't a solution as I need to know why it won't recognize/match the data already present as this is example data that I need to work with in my App..
Attachments
Untitled 1.livecode.zip
(1.19 KiB) Downloaded 312 times

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: contains...with 2 Variables

Post by Simon » Wed Jan 16, 2013 8:53 pm

I checked out your stack, changed the code to:

Code: Select all

on test
   put word 2 of fld "Bob" into tSource --note word not line
   put word 1 of fld "Nakia" into tKey --same as above
   if tKey is in tSource then --changed see below
      answer "Yep found it"
   else
      answer "Nope can't find it"
   end if
end test
You had "if tKey is in line 2 of tSource then", I'm not sure why you wanted line 2 though, it only had 1 line.

In the end the trouble is that there is a cr/linefeed after Test2.pdf in fld "Nakia", maybe use chartonum to figure out what it actually is.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: contains...with 2 Variables

Post by Nakia » Wed Jan 16, 2013 10:05 pm

Thanks Simon..

So how did you figure out that there was a CR/LF on the end of that?
and what is the best way to remove that from a Variable, line by line

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: contains...with 2 Variables

Post by Simon » Wed Jan 16, 2013 10:24 pm

Hi Nakia,
I copied and pasted fld "Nakia" into notepad and notice the extra line.
Actually I did run the charToNum and found both ASCII 13 and 10 in the fld.
and what is the best way to remove that from a Variable, line by line
Well I'm not sure you want to as it will put all your lines into a single line.
Here is an example of what I receive when I retrieve the file list
"01-16-13 10:17AM 142478 Test2.pdf"
I'm guessing there are more lines:
01-16-13 10:17AM 142478 Test2.pdf
01-16-13 10:15AM 102478 Test3.pdf
etc.
I'd do:

Code: Select all

repeat for each line tLine in fileList
put the last word of tLine & cr after tVar
end repeat
delete the last char of tVar --remove the extra cr 
Simon EDIT: Using "word" says there can't be spaces in your file names, I'll have to think...
EDIT 2: OK you said that there were tabs between the items so:

Code: Select all

set itemDel to tab
repeat for each line tLine in fileList
put the last item of tLine & cr after tVar
end repeat
delete the last char of tVar --remove the extra c
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: contains...with 2 Variables

Post by Klaus » Wed Jan 16, 2013 10:31 pm

Hi friends,

this should do:
...
replace CRLF with CR in tTextFromServer
...
:D


Best

Klaus

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: contains...with 2 Variables

Post by Simon » Wed Jan 16, 2013 10:42 pm

Oh Klaus!
You and your crazy ways! :D
Works great!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply