• 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
Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]


  • Subject: Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
  • From: Emile Schwarz <email@hidden>
  • Date: Sun, 26 Oct 2008 15:30:22 +0100

Hi all,

So, “Now is the time” for me to give:


Luther answer makes my brain overwork and the idea to implement functions that I need (habit to use) and so here is a Mid(Source,Start,End) function came to me.


Of course, AppleScript does not let me use the names (words) I want, so I used others.

The first line ask the StringMid function to display "les", the defined function StringMid do the job.

"Salut les filles.": Hi girls or Hi girlies…


display dialog my StringMid("Salut les filles.", 7, 3)

-- ********** ********** ********** ********** **********
--
-- “StringMid(StringSource, StartCount, CharCount)” definition:
--
on StringMid(StringSource, StartCount, CharCount)
-- StringSource: the string you want to extract characters from
-- StartCount: the first character to be returned
-- CharCount: the number of characters you want to return
-- TargetString: the stripped string to be returned

-- declare some variables
set TargetString to ""
set StringEnd to 0
set StringLength to 0

-- compute the source string length
set StringLength to count of characters in StringSource

-- compute the string offset
set StringEnd to (StartCount + CharCount) - 1 -- [1]

-- store the wanted string
set TargetString to (characters StartCount thru StringEnd of StringSource) as string


-- return the wanted string
return TargetString
end StringMid



If there is a possible optimisation, please share.

Emile

[1] else I get CharCount + 1 ! That is because StartCount points to 'l', and I ask for three characters, so StartCount + 3. I think so.
_______________________________________________
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: Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
      • From: Skeeve <email@hidden>
  • Prev by Date: Re: How can I format an integer ?
  • Next by Date: Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
  • Previous by thread: Re: AppleScript strings fail
  • Next by thread: Re: Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
  • Index(es):
    • Date
    • Thread