Page 1 of 1
contains...with 2 Variables
Posted: Wed Jan 16, 2013 7:02 am
by Nakia
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 7:19 am
by Nakia
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?
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 7:39 am
by dave_probertGA6e24
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:
to get the effect you want.
Cheers,
Dave
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 7:52 am
by Nakia
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..
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 7:57 am
by Nakia
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:
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....
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:08 am
by Nakia
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:53 am
by shaosean
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..
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 11:12 am
by Nakia
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 11:39 am
by Nakia
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
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..
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 8:53 pm
by Simon
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:05 pm
by Nakia
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:24 pm
by Simon
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
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:31 pm
by Klaus
Hi friends,
this should do:
...
replace CRLF with CR in tTextFromServer
...
Best
Klaus
Re: contains...with 2 Variables
Posted: Wed Jan 16, 2013 10:42 pm
by Simon
Oh Klaus!
You and your crazy ways!
Works great!
Simon