Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-05 Thread Geoff Canyon via use-livecode
I've updated my GitHub to the following, which adopts Brian's "starts with" (I can't count how many times I've had to re-remember that "starts with" is faster than comparing to char 1 through ) and added minor optimizations to the wrapping-up code. gc function allOffsets D,S,pCase,pNoOverlaps

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-05 Thread Geoff Canyon via use-livecode
On Sun, Nov 4, 2018 at 7:11 PM Mark Wieder via use-livecode < use-livecode@lists.runrev.com> wrote: > > If you're looking for 'romeo' in pText, would you set pOverlaps to true > or to false? I'd set it to false, there's no way for "romeo" to overlap. But even if I were looking for "radar",

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-05 Thread Geoff Canyon via use-livecode
On Sun, Nov 4, 2018 at 7:42 PM Bob Sneidar via use-livecode < use-livecode@lists.runrev.com> wrote: > Simply add 1 to the last offset pointer. If after the first iteration you > return 1, then set the charsToSkip to 2 instead of offset + > len(searchString) if you take my meaning. > > Bob S >

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Brian Milby via use-livecode
Here's an image of the stack in my fork of the repo: https://github.com/bwmilby/alloffsets/blob/bwm/bwm/stack_allOffsets_card_id_1018.png On Sun, Nov 4, 2018 at 10:07 PM Brian Milby wrote: > I’m working on an update to the stack now. Moving buttons to the left side > to make it easier to add

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Brian Milby via use-livecode
I’m working on an update to the stack now. Moving buttons to the left side to make it easier to add more. Thanks, Brian On Nov 4, 2018, 10:02 PM -0600, Mark Wieder via use-livecode , wrote: > On 11/4/18 4:45 PM, Brian Milby via use-livecode wrote: > > My updated solution always looks for

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Mark Wieder via use-livecode
On 11/4/18 4:45 PM, Brian Milby via use-livecode wrote: My updated solution always looks for overlap but if none are found it uses optimized versions of the search (private functions instead of inside the main function). I special case for no overlap and a single overlap in the delimiter. It

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Bob Sneidar via use-livecode
Simply add 1 to the last offset pointer. If after the first iteration you return 1, then set the charsToSkip to 2 instead of offset + len(searchString) if you take my meaning. Bob S > On Nov 2, 2018, at 17:43 , Geoff Canyon via use-livecode > wrote: > > I like that, changing it. Now

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Mark Wieder via use-livecode
On 11/4/18 6:49 PM, Geoff Canyon via use-livecode wrote: I'm not sure I agree that it would be so unlikely to know that overlaps won't occur (or that it's unreasonable to not want them). If I'm looking for every instance of "romeo" in romeo and juliet, then obviously I'm not expecting, nor do I

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Geoff Canyon via use-livecode
On Sun, Nov 4, 2018 at 4:34 PM Mark Wieder via use-livecode < use-livecode@lists.runrev.com> wrote: > On 11/4/18 10:40 AM, Geoff Canyon via use-livecode wrote: > > I also added a "with overlaps" option. > > My problem with the pWithOverlaps parameter is that is requires a priori > knowledge of

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Brian Milby via use-livecode
My updated solution always looks for overlap but if none are found it uses optimized versions of the search (private functions instead of inside the main function). I special case for no overlap and a single overlap in the delimiter. It is about the same speed as Geoff’s. Thanks, Brian On Nov

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Mark Wieder via use-livecode
On 11/4/18 10:40 AM, Geoff Canyon via use-livecode wrote: I also added a "with overlaps" option. My problem with the pWithOverlaps parameter is that is requires a priori knowledge of the data being consumed. If you already know there are overlaps then you'd set the parameter to true. If you

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Brian Milby via use-livecode
Logic matches my solution. I also validated my solution using just the offset function. Speed hit for with overlap is similar. One possible optimization: put kList is not empty into pWithOverlaps If with overlaps was requested but the source delimiter did not contain any overlaps, then the

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-04 Thread Geoff Canyon via use-livecode
Alex, good catch! The code below and at https://github.com/gcanyon/alloffsets now puts a stop character after the string to prevent the error you found. I also added a "with overlaps" option. I think this is correct, and about as efficient as possible, but thanks to anyone who finds a bug or a

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-03 Thread Brian Milby via use-livecode
I've posted a binary stack version that includes my version. I cloned and made a "bwm" branch in my clone. Here's the direct link to the script with the posted code (updated to use private functions):

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-03 Thread Brian Milby via use-livecode
Good catch Alex. My code was closer, but didn't handle repeating characters correctly. Here is an updated version. function allOffsets2 D,S,pCase local dLength, C, R -- returns a comma-delimited list of the offsets of D in S set the caseSensitive to pCase is true set the itemDel to

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-03 Thread Alex Tweedly via use-livecode
Hi Geoff, unfortunately the impact of overlapping delimiter strings is more severe than simply not finding them. The code on github gets the wrong answer if there is an overlapping string at the very end of the search string, e.g. alloffsets("", "a")    wrongly gives  1,5,10 I

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Brian Milby via use-livecode
Here is something... probably needs some optimization function allOffsets2 D,S,pCase local dLength, C, R -- returns a comma-delimited list of the offsets of D in S set the caseSensitive to pCase is true set the itemDel to D put length(D) into dLength put 1 - dLength into C

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Alex Tweedly via use-livecode
Oh dear - answering my own posts rarely a good sign :-) On 03/11/2018 02:10, Alex Tweedly via use-livecode wrote: On 03/11/2018 00:43, Geoff Canyon via use-livecode wrote: One thing I don't see how to do without significantly impacting performance is to return all offsets if there are

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Alex Tweedly via use-livecode
On 03/11/2018 00:43, Geoff Canyon via use-livecode wrote: I like that, changing it. Now available at https://github.com/gcanyon/alloffsets One thing I don't see how to do without significantly impacting performance is to return all offsets if there are overlapping strings. For example:

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Geoff Canyon via use-livecode
I like that, changing it. Now available at https://github.com/gcanyon/alloffsets One thing I don't see how to do without significantly impacting performance is to return all offsets if there are overlapping strings. For example: allOffsets("aba","abababa") would return 1,5, when it might be

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Bob Sneidar via use-livecode
how about allOffsets? Bob S > On Nov 2, 2018, at 09:16 , Geoff Canyon via use-livecode > wrote: > > All of those return a single value; I wanted to convey the concept of > returning multiple values. To me listOffset implies it does the same thing > as itemOffset, since items come in a list.

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Geoff Canyon via use-livecode
All of those return a single value; I wanted to convey the concept of returning multiple values. To me listOffset implies it does the same thing as itemOffset, since items come in a list. How about: offsets -- not my favorite because it's almost indistinguishable from offset offsetsOf -- seems a

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-02 Thread Bob Sneidar via use-livecode
It probably should be named listOffset, like itemOffset or lineOffset. Bob S > On Nov 1, 2018, at 17:04 , Geoff Canyon via use-livecode > wrote: > > Nice! I *just* finished creating a github repository for it, and adding > support for multi-char search strings, much as you did. I was coming

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-01 Thread Geoff Canyon via use-livecode
Nice! I *just* finished creating a github repository for it, and adding support for multi-char search strings, much as you did. I was coming to the list to post the update when I saw your post. Here's the GitHub link: https://github.com/gcanyon/offsetlist Here's my updated version: function

Re: How to find the offset of the last instance of a repeating character in a string? (Geoff Canyon)

2018-11-01 Thread Niggemann, Bernd via use-livecode
Hi Geoff, thank you for this beautiful script. I modified it a bit to accept multi-character search string and also for case sensitivity. It definitely is a lot faster for unicode text than anything I have seen. - function offsetList D,S, pCase -- returns a

Re: How to find the offset of the last instance of a repeating character in a string?

2018-11-01 Thread Geoff Canyon via use-livecode
I was curious if using the itemDelimiter might work for this, so I wrote the below code out of curiosity; but in my quick testing with single-byte characters it was only about 30% faster than the above methods, so I didn't bother to post it. But Ben Rubinstein just posted about a terrible

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Kay C Lan via use-livecode
On Tue, Oct 30, 2018 at 2:33 AM Keith Clarke via use-livecode wrote: > > I’m trying to separate paths & pages from a list of URLs and so looking to > identify the position of the last ‘/‘ character. > If that is all you are after then I think setting the itemDelimiter to "/" and separating the

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Alex Tweedly via use-livecode
On 29/10/2018 22:32, Mark Wieder via use-livecode wrote: On 10/29/2018 08:32 AM, Keith Clarke via use-livecode wrote: I’m trying to separate paths & pages from a list of URLs and so looking to identify the position of the last ‘/‘ character. How about function rightmostSlashOf p   

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Alex Tweedly via use-livecode
"toplevel/somename/another/somename" On 29/10/2018 22:32, Mark Wieder via use-livecode wrote: On 10/29/2018 08:32 AM, Keith Clarke via use-livecode wrote: I’m trying to separate paths & pages from a list of URLs and so looking to identify the position of the last ‘/‘ character. function

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Bob Sneidar via use-livecode
Oh right you are! Bob S > On Oct 29, 2018, at 16:04 , Mark Wieder via use-livecode > wrote: > > On 10/29/2018 03:55 PM, Bob Sneidar via use-livecode wrote: >> That will only give him the item, not the character position. > > Nope. It returns the position. > > -- > Mark Wieder >

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Mark Wieder via use-livecode
On 10/29/2018 03:55 PM, Bob Sneidar via use-livecode wrote: That will only give him the item, not the character position. Nope. It returns the position. -- Mark Wieder ahsoftw...@gmail.com ___ use-livecode mailing list

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Bob Sneidar via use-livecode
That will only give him the item, not the character position. But it's a start. You can now get the number of characters of item 1 to -2 of pText +1. I didn't know the text you were searching had regular delimiters, and you were searching for the last delimiter. That makes things *much* easier.

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Mark Wieder via use-livecode
On 10/29/2018 08:32 AM, Keith Clarke via use-livecode wrote: I’m trying to separate paths & pages from a list of URLs and so looking to identify the position of the last ‘/‘ character. function rightmostSlashOf pText set the itemdelimiter to "/" return offset(item -1 of pText, pText)

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Bob Sneidar via use-livecode
In dBase/Foxpro they had an AT function synonymous (roughly) with our offset function. They also had a RAT (Reverse AT) function. I needed something like this many moons ago. What I did to get all occurrences is I have a "pointer" variable I maintain with the position of the first character

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Bob Sneidar via use-livecode
Looks like Devin beat me to it. :-) Bob S > On Oct 29, 2018, at 08:49 , Devin Asay via use-livecode > wrote: > > On Oct 29, 2018, at 9:32 AM, Keith Clarke via use-livecode > wrote: >> >> Folks, >> Is there a simple way to find the offset of a character from the ‘right’ end >> of a

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Keith Clarke via use-livecode
Perfect, thanks Devin - I was hoping to see ‘offsets’ in the docs under ‘offset’, so this will do nicely! :-) Best, Keith > On 29 Oct 2018, at 15:49, Devin Asay via use-livecode > wrote: > > On Oct 29, 2018, at 9:32 AM, Keith Clarke via use-livecode > wrote: >> >> Folks, >> Is there a

Re: How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Devin Asay via use-livecode
On Oct 29, 2018, at 9:32 AM, Keith Clarke via use-livecode wrote: > > Folks, > Is there a simple way to find the offset of a character from the ‘right’ end > of a string, rather than the beginning - or alternatively get a list of all > occurrences? > > I’m trying to separate paths & pages

How to find the offset of the last instance of a repeating character in a string?

2018-10-29 Thread Keith Clarke via use-livecode
Folks, Is there a simple way to find the offset of a character from the ‘right’ end of a string, rather than the beginning - or alternatively get a list of all occurrences? I’m trying to separate paths & pages from a list of URLs and so looking to identify the position of the last ‘/‘