LineIndex

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
billenright123
Posts: 5
Joined: Thu Apr 04, 2013 11:08 am

LineIndex

Post by billenright123 » Thu Apr 04, 2013 11:23 am

I have numerous stacks dating back to Hypercard era that I have tweaked over the years and work fine in Revolution.

One of the mainstays is an old XCMD called LineIndex.
- Example "put LineIndex("Location:", it) into locx"
This would give me a list of all the line numbers within the chunk "It" that contain the String "Location:"

However, LiveCode 5.5 introduced a new keyword - LineIndex.
This seems to trump the old XCMD.

So, my question is: Can I disable this new keyword (or rename the old XCMD?

Any thoughts?
Thanks

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: LineIndex

Post by Dixie » Thu Apr 04, 2013 11:45 am

Have a look at 'lineOffset' in the dictionary...

Dixie

billenright123
Posts: 5
Joined: Thu Apr 04, 2013 11:08 am

Re: LineIndex

Post by billenright123 » Thu Apr 04, 2013 11:53 am

Thanks for the post.

LineOffset only returns a single instance of the found string.
It does not provide information about any additional occurrences of the text in the chunk.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: LineIndex

Post by Dixie » Thu Apr 04, 2013 12:28 pm

Yes, it does... read a little closer...

lineOffset(lineToFind,stringToSearch[,linesToSkip])

If you specify how many linesToSkip, the lineOffset function skips the specified number of lines in the stringToSearch. The value returned is relative to this starting point instead of the beginning of the stringToSearch.... so, put the 'lineOffset' function' in a repeat loop, using the 'linesToSkip' parameter after each find...

Dixie

billenright123
Posts: 5
Joined: Thu Apr 04, 2013 11:08 am

Re: LineIndex

Post by billenright123 » Thu Apr 04, 2013 12:37 pm

I will give that a try.

Any thoughts on salvaging my old XCMD?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: LineIndex

Post by bn » Thu Apr 04, 2013 1:56 pm

Hi billenright123,

here is a little stack that shows how to use lineOffset repeatedly.
That is at first a little tricky to do.
lineOffsetStack.livecode.zip
(1.29 KiB) Downloaded 281 times
Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: LineIndex

Post by dunbarx » Thu Apr 04, 2013 2:13 pm

Hi.

What everyone said. The lineOffset function in a repeat loop works as advertised.

I wrote a LC function based on the need to have what Rinaldi gave us in HC with "fullFind". It is in a library in use, just as fullFind itself is for my HC world.

Code: Select all

function revFullFind tText,tFind,exactly --RETURNS LINE NUMBER & "," & WORD NUMBER
   put 0 into counter
   switch exactly
      case "true"
      case empty
         repeat for each line tline in tText
            add 1 to counter
            if tFind = tline then
               put counter & return after tResult
            end if
         end repeat
         break
      case "false"
         repeat for each line tline in tText
            add 1 to counter
            if tFind is in tline then
               repeat with y = 1 to the number of words in tLine
                  if word y of tLine = tFind then put y & "," after temp
               end repeat
               delete last char of temp
               put counter & "," & temp & return after tResult
               put "" into temp
            end if
         end repeat
         break
   end switch
   return tResult
end revFullFind
It returns a list of lines containing the text, and the word number within those lines. Easy.
Craig Newman

billenright123
Posts: 5
Joined: Thu Apr 04, 2013 11:08 am

Re: LineIndex

Post by billenright123 » Thu Apr 04, 2013 10:57 pm

All - Thanks!
Great stuff

Bill

Post Reply