Thanks for this, although I’m not sure I understand. In fact I am sure I don’t. I know how amazingly fast the array method is, I use it elsewhere in the same stack, and it is great.
I also don’t understand the distinction between line numbering and indexing. If I was guessing, I would go for line numbering prepends to each line in a text field a number, and indexing is adding a numerical key to a database or array. The former is what I described in my original post. The reason the issue arrises is because some of the text/chat message records I referred to have the date and time stamps stripped out. So in the following exchange… 1757 Shadowknave: U gotta b there 1758 What_goes_Moo: kk 1759 Shadowknave: no let down? 1760 What_goes_Moo: kk 1761 Shadowknave: U b there 8? 1762 What_goes_Moo: I wil … lines 2 and 4 would be identical but for the line number I added via the script. And of course, the integrity of the dialogue must be maintained. I had believed that collapsing duplicates and alphabetising are unavoidable with split. If there is an array method which doesn’t mess with the text message order or content, then I would be delighted. Is that what this is below, but I haven’t appreciated it? Cheers, David G > On 28 Oct 2018, at 1:47 pm, hh via use-livecode > <use-livecode@lists.runrev.com> wrote: > >> David G. wrote: >> Thanks Geoff, I did play with Split, but one of the reasons for numbering >> is to make any identical lines unique. With split, for any that are not, >> all but one is deleted. So definitely not the result I wanted. > > I am not Geoff (who played with the simple array methods I suggested). > But your post attacks indirectly my suggested handlers below as wrong, as if > they would not hit your question. > > My handlers (which are at least 600 times faster than your first script) > output exactly the same what your first script outputs, seen apart from the > optional delimiter. > >> So definitely not the result I wanted. > LOL: You mention above the "unique"-side-condition the first time... > > With your new side condition from above several others (and I) know also > how this is doable very fast, once again using arrays. And it is an > invertible method, that is, the original text is exactly restorable. > > But first post YOU your new handler, to see *all* your new side conditions, > that is, or to see what you really want: > Certainly not a line numbering, rather indexing a text file. > >>>>> David G. wrote: [This is the first script] >>>>> However…. >>>>> Sometimes I want to prefix each line with the line number, and do this: >>>>> >>>>> put 1 into tcount >>>>> repeat for each line j in it >>>>> put tcount & j into line tcount of it >>>>> put tcount + 1 into tcount >>>>> set the thumbpos of scrollbar "filterprog" to tcount >>>>> end repeat >>>>> put it into field “numberedtext” >>>>> >>>>> I use ‘it’ because of a dim memory (superstition? Myth?) from long ago >>>>> that >>>>> it is faster than an arbitrarily named variable. Still, the whole process >>>>> is pretty darned slow. Any brilliant suggestions? >> >>> Geoff C. wrote: >>> And of course if retaining the order isn't critical you could just go with: >>> >>> function numberText T,D >>> split T by cr >>> combine T by cr and D >>> return T >>> end numberText >>> >>> function unNumberText T,D >>> split T by cr and D >>> combine T by cr >>> return T >>> end unNumberText >> >>>> Hermann H. wrote: >>>> 1. Besides removing scroll-update, which takes most of the time, you could >>>> try the following array-methods (which are essentially from my stack >>>> >>>> http://forums.livecode.com/viewtopic.php?p=101301#p101301 >>>> , see there >>>> card "LineNums, tab "Nb2"). >>>> >>>> This needs here on a medium fast machine (Mac mini, 2.5GHz) in average >>>> with LC 9.0.1 (which is at about 30% faster than LC 8.1.10 with that): >>>> >>>> 680 ms for 10000 lines to add the line numbers, >>>> 650 ms for 10000 lines to remove the line numbers, >>>> both incl. the field update (a lot of long lines are to break). >>>> >>>> -- Add "inline line numbers" [-hh fecit, 2014] >>>> -- Uses separator ": " (In LC 6 use one single char, remove below needs >>>> that) >>>> on mouseUp >>>> lock screen; lock messages >>>> put the millisecs into m1 >>>> set cursor to watch >>>> put fld "IN" into T >>>> split T by return >>>> put the keys of T into K >>>> sort K numeric >>>> repeat for each line L in K >>>> put cr & L & ": " & T[L] after S --> change separator here >>>> end repeat >>>> set text of fld "OUT" to char 2 to -1 of S >>>> put -1+the num of lines of S & " lines: " & \ >>>> the millisecs -m1 & " ms" into fld "timing" >>>> end mouseUp >>>> >>>> -- Remove "inline line numbers" [-hh fecit, 2014] >>>> -- Uses separator ": " (the above, in LC 6 you have to use one single char) >>>> on mouseUp >>>> lock screen; lock messages >>>> put the millisecs into m1 >>>> set cursor to watch >>>> put the text of fld "OUT" into S >>>> split S by return and ": " --> change separator here >>>> put the keys of S into K >>>> sort K numeric >>>> repeat for each line L in K >>>> put cr & S[L] after T >>>> end repeat >>>> put char 2 to -1 of T into fld "IN2" >>>> put -1+the num of lines of T & " lines: " & \ >>>> the millisecs -m1 & " ms : " & (fld "IN2" is fld "IN") into fld >>>> "timing" >>>> end mouseUp > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode