Dictionary error for "lineOffset"

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Dictionary error for "lineOffset"

Post by dunbarx » Mon Jan 27, 2025 11:22 pm

The lineOffset function returns the line that contains a specified string. All well and good, I use it all the time.

But the dictionary says:
The value returned by the lineOffset function is the number of the line where lineToFind first appears in stringToSearch. If the lineToFind is not in stringToSearch, the lineOffset function returns zero. If the lineToFind spans more than one line, the lineOffset function always returns zero, even if the lineToFind appears in the stringToSearch.
May I assume the terms "lineToFind" and "stringToSearch" in the above are switched? :roll:

Craig

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Dictionary error for "lineOffset"

Post by SparkOut » Tue Jan 28, 2025 8:56 am

I think lineToFind is the needle and stringToSearch is the haystack.
So you can't search for
"Something I
want to get
the line number for" in the haystack, because it can't return a single line for a multiline needle.

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

Re: Dictionary error for "lineOffset"

Post by dunbarx » Tue Jan 28, 2025 4:00 pm

Sparkout.

I can see what you mean. But for me that is very odd phrasing and thinking.

craig

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Dictionary error for "lineOffset"

Post by Klaus » Tue Jan 28, 2025 6:04 pm

My "memory hook" for "Lineoffset" is: lineoffset(what,where)
So for me the dictionary entry is correct.

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

Re: Dictionary error for "lineOffset"

Post by dunbarx » Tue Jan 28, 2025 7:50 pm

Klaus.
My "memory hook" for "Lineoffset" is: lineoffset(what,where)
Exactly. "What" to be found in "Where". "What" is the stringToFind. "Where" is dataToSearch.

I read that as: lineOffset(stringToFind,dataToSearch). Because we are trying to locate the stringToFind in the dataToSearch. The function actually works that way. But the dictionary says the opposite, lineOffset(lineToFind, stringToSearch)

The dictionary says "... number of the line where lineToFind first appears in stringToSearch."

Really? We want to find the line we need to find in the LineToFind? And the string "seed" is stringToSearch? Should be "stringToSearchFor"?

We are not searching a body of text for lineToFind, we are searching for stringToSearch. We do not find it (our string to search) in stringToSearch, we find it (hopefully) in lineToFind.

I say it should read "... number of the line where stringToFind first appears in dataToSearch."
OK, OK, semantics all. :wink:

Craig

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Dictionary error for "lineOffset"

Post by SparkOut » Tue Jan 28, 2025 9:26 pm

Ah, yes it's more the ambiguity of the example variable names chosen for the function arguments in the dictionary, eg you are reading as stringToSearch[for] rather than stringToSearch[within]
The dictionary is indeed actually correct but could be clearer, without a doubt.

Post Reply