Finding among column1 (wordchunk 1) of text file ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Finding among column1 (wordchunk 1) of text file ?

Post by shawnblc » Wed Apr 24, 2019 4:11 pm

I'm trying to find just the text in column 1 of the text file, having difficulty. I've tried to use word 1, segment,. Can you give me some hints on the how to process this?

Code: Select all

put fld "fld1" into tFile1
put URL "http://domain.com/1.text" into tFile
if tFile1 is among the words of tFile then
....
My text file looks like this (set itemdel as TAB)

Code: Select all

sometext here		somemoretext		somemore text is here

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Finding among column1 (wordchunk 1) of text file ?

Post by Klaus » Wed Apr 24, 2019 4:23 pm

Hi Shawn,

you should try this:

Code: Select all

...
put URL "http://domain.com/1.text" into tFile
if tFile contains tFile1 then
...
But that will also be true if tFile1 may be found in column 2 or 3!
I would use a repeat loop:

Code: Select all

...
set itemdel to TAB
repeat for each line tLine in tFile
  if item 1 of tLine = tFile1 then
    ## Found it, do something
   end if
end repeat
...
Best

Klaus

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm
Location: USA

Re: Finding among column1 (wordchunk 1) of text file ?

Post by shawnblc » Wed Apr 24, 2019 11:22 pm

I keep getting no, no matter what. Racking my brain.

Code: Select all

on mouseUp
   put fld "fld1" into tLine
   
   set itemDel to TAB
   put URL "http://*********.on-rev.com/testing123.txt" into tFile
   --answer tFile - shows the file
   repeat for each line tLine in tFile
      if item 1 of tLine = tFile then
         answer "Yes" else
      answer "No"
      end if
   end repeat
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Finding among column1 (wordchunk 1) of text file ?

Post by dunbarx » Thu Apr 25, 2019 12:31 am

Hi.

You are comparing the first item in each line with the entire contents of tFile, the result of the URL call. That cannot be right.

Craig

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Finding among column1 (wordchunk 1) of text file ?

Post by Klaus » Thu Apr 25, 2019 9:28 am

That is not what I wrote! 8)
I used your variables -> tFile and tFile1 as in your posting, so please look again!

This will work as in my fist proposal:

Code: Select all

on mouseUp
 ## Please look up REPEAT FOR EACH in the dictionary
 #########  put fld "fld1" into tLine
 
  ##!!!!!!!
  put fld "fld1" into tFile1
  ## !!!!!!
   
   set itemDel to TAB
   put URL "http://*********.on-rev.com/testing123.txt" into tFile
   repeat for each line tLine in tFile
      if item 1 of tLine = tFile1 then
         answer "Yes" 
         
         ## Here is the time to:
         exit repeat
      else
        answer "No"
      end if
   end repeat
end mouseUp

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”