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

Bob Sneidar bobsneidar at iotecdigital.com
Mon Oct 29 18:23:12 EDT 2018


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 after the last instance of the string found. But to get the actual position in the original text, you have to add the pointer to the offset like so:

put 0 into tPointer
repeat
	put offset(tVar, tTextChunk, tPointer) into tNextPos
	if tNextPos = 0 then exit repeat
	add tPointer to tNextPos
	put char tNextPos to tNextPos + length(tVar) of tTextChunk into aFoundChunks [tNextPos] [length(tVar)]
	put tNextPos + length(tVar) +1 into tPointer
end repeat

Something along those lines. Not tested, but you get the idea. 

Bob S


> On Oct 29, 2018, at 08:32 , Keith Clarke via use-livecode <use-livecode at lists.runrev.com> 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 from a list of URLs and so looking to identify the position of the last ‘/‘ character.
> 
> Thanks & regards,
> Keith
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list