Accessing the last item in a line

Mark Wieder mwieder at ahsoftware.net
Mon Aug 22 17:57:27 EDT 2011


Jacque-

Monday, August 22, 2011, 8:20:46 AM, you wrote:

> It's come up many times before. The delimiter belongs to the item before
> it. That's true of both items and lines. How many lines are in each of
> these examples:

> This is line one. <cr>
> This is line two.


> This is line one.<cr>
> This is line two.<cr>

> I think most would agree that the second example still has only two 
> lines, regardless of the trailing return character. If you ask for line
> 3 in either example, you will get empty. For your project, asking for
> item 3 will also return empty, so that's how you know.

The problem comes not from getting an ordinal item from a list, but
from getting the last item explicitly. And in that case, "the last
item" or "item -1" is shorthand for "the last item that isn't empty".

set the itemdelimiter to "/"
item -1 of "http://www.domain.com/folder/file" -- is "file"
item -1 of "http://www.domain.com/folder" -- is "folder"
item -1 of "http://www.domain.com/folder/" -- is also "folder"

the last example makes less sense to me. It should return empty.

-- 
-Mark Wieder
 mwieder at ahsoftware.net





More information about the Use-livecode mailing list