LineIndex
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 5
- Joined: Thu Apr 04, 2013 11:08 am
LineIndex
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
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
Re: LineIndex
Have a look at 'lineOffset' in the dictionary...
Dixie
Dixie
-
- Posts: 5
- Joined: Thu Apr 04, 2013 11:08 am
Re: LineIndex
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.
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.
Re: LineIndex
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
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
-
- Posts: 5
- Joined: Thu Apr 04, 2013 11:08 am
Re: LineIndex
I will give that a try.
Any thoughts on salvaging my old XCMD?
Any thoughts on salvaging my old XCMD?
Re: LineIndex
Hi billenright123,
here is a little stack that shows how to use lineOffset repeatedly.
That is at first a little tricky to do.
Kind regards
Bernd
here is a little stack that shows how to use lineOffset repeatedly.
That is at first a little tricky to do.
Kind regards
Bernd
Re: LineIndex
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.
It returns a list of lines containing the text, and the word number within those lines. Easy.
Craig Newman
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
Craig Newman
-
- Posts: 5
- Joined: Thu Apr 04, 2013 11:08 am
Re: LineIndex
All - Thanks!
Great stuff
Bill
Great stuff
Bill