• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Position of an element in a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Position of an element in a list


  • Subject: Position of an element in a list
  • From: Olivier MARTINEAU <email@hidden>
  • Date: Mon, 31 Jul 2017 15:54:36 +0000
  • Thread-topic: Position of an element in a list

Hi everyone,


Just wanted to share some code.

I find it weird that I couldn't find any native function that would return the
position of a element in a list...

Maybe I overlooked something.

But I needed it, so I took the code of Emmanuel Levy and made it a bit more
fail-proof.

(in his code, position of "TT" in list {"TTT"} would give 1, which was not good
to me)



on positionInList(theItem, theList) -- credits Emmanuel Levy

set MARK to "◊" -- of course you won't be able to look for such character's
position in list, so choose one that isn't used

set ASTID to AppleScript's text item delimiters

set AppleScript's text item delimiters to MARK & return & MARK

set theList to MARK & theList & MARK

log theList

try

set theIndex to count paragraphs of text 1 thru (offset of (MARK & theItem &
MARK) in theList) of theList

on error

set theIndex to 0

end try

set AppleScript's text item delimiters to ASTID

return theIndex

end positionInList


set myList to {"TTT", 1, 67, "TT", 8}

my positionInList("TT", myList)


Enjoy !

😊


Olivier Martineau
Chef de projet DSI

Direct : 04 77 42 38 16
Mobile : 06 61 92 30 67
E-mail :
email@hidden<mailto:email@hidden>

(absent les mercredis et vendredis après-midi)

[http://gutenbergbaseline.gutenberg-networks.com/LogoGUNbaseline.jpg]<http://www.gutenberg-networks.com/>
34, rue Necker
42029 Saint-Étienne Cedex 1
www.gutenberg-networks.com<http://www.gutenberg-networks.com/>


-- Pensez à l'environnement, n'imprimez ce message que si nécessaire --


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Position of an element in a list
      • From: Jim Underwood <email@hidden>
References: 
 >Save of CSV Formatted File Fails on Excel 15.36 under Sierra (From: Thomas Maffucci <email@hidden>)
 >Re: Save of CSV Formatted File Fails on Excel 15.36 under Sierra (From: Yvan KOENIG <email@hidden>)
 >Re: Save of CSV Formatted File Fails on Excel 15.36 under Sierra (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Save of CSV Formatted File Fails on Excel 15.36 under Sierra
  • Next by Date: Re: Position of an element in a list
  • Previous by thread: Re: Save of CSV Formatted File Fails on Excel 15.36 under Sierra
  • Next by thread: Re: Position of an element in a list
  • Index(es):
    • Date
    • Thread