Something like charIndex, but in a variable...

Peter Brigham pmbrig at gmail.com
Thu Apr 30 12:55:18 EDT 2015


Here's a function I use all the time, which may come in handy:


function offsets str, pContainer
   -- returns a comma-delimited list of all the offsets of str in pContainer
   -- returns 0 if not found
   -- note: offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
   --     ie, overlapping offsets are not counted
   -- note: to get the last occurrence of a string in a container (often
useful)
   --     use "item -1 of offsets(...)"
   -- by Peter M. Brigham, pmbrig at gmail.com — freeware

   if str is not in pContainer then return 0
   put 0 into startPoint
   repeat
      put offset(str,pContainer,startPoint) into thisOffset
      if thisOffset = 0 then exit repeat
      add thisOffset to startPoint
      put startPoint & comma after offsetList
      add length(str)-1 to startPoint
   end repeat
   return item 1 to -1 of offsetList -- delete trailing comma
end offsets


-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Thu, Apr 30, 2015 at 10:48 AM, J. Landman Gay <jacque at hyperactivesw.com>
wrote:

> Will the offset function work?
>
> put the number of chars in line 1 to 14 of tVar into tCount
> put offset(startChar, line 15 of tVar)  + tCount into tStart
> put offset(endChar, line 15 of tVar)  + tCount into tEnd
>
>
> On April 30, 2015 3:07:05 AM CDT, Malte Brill <revolution at derbrill.de>
> wrote:
> >Hi all,
> >
> >I need to find the start and end character of chuncks in a variable. If
> >we are in a field we can use charIndex for that. However, in a variable
> >I have no good idea on how to do something similar to
> >
> >get charIndex(token 7 of line 15 of field „myField“)
> >
> >
> >Any ideas?
> >
> >All the best,
> >
> >Malte
> >
> >
> >_______________________________________________
> >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
>
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
>
> _______________________________________________
> 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