• 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
Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”


  • Subject: Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
  • From: Emile Schwarz <email@hidden>
  • Date: Sun, 26 Oct 2008 15:40:04 +0100

Here are the two other functions to work with string (that I missed, more or less):


display dialog my StringLeft("Salut les filles.", 5) -- Display: “Salut” display dialog my StringRight("Salut les filles.", 7) -- Display: “filles.”


-- ********** ********** ********** ********** **********
--
-- “StringLeft(StringSource, CharCount)” handler definition
on StringLeft(StringSource, CharCount)
-- StringSource: the string you want to extract characters from
-- CharCount: the number of characters you want to get back
-- TargetString: the stripped string to be returned
-- declare some variables
set TargetString to ""
-- store the wanted string
set TargetString to (characters 1 thru CharCount of StringSource) as string
-- return the wanted string
return TargetString
end StringLeft



-- ********** ********** ********** ********** **********
--
-- “StringRight(StringSource, CharCount)” handler definition
--
on StringRight(StringSource, CharCount)
-- StringSource: the string you want to extract characters from
-- CharCount: the number of characters you want to get back
-- TargetString: the stripped string to be returned
-- declare some variables
set TargetString to ""
set StringOffset to 0
set StringLength to 0
-- compute the source string length
set StringLength to count of characters in StringSource
-- compute the string offset
set StringOffset to (StringLength - CharCount) + 1
-- store the wanted string
set TargetString to (characters StringOffset thru ((StringOffset - 1) + CharCount) of StringSource) as string
-- return the wanted string
return TargetString
end StringRight





Note that if you place all handlers in a document and put on the doc begin:

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

You will get three dialogs that said:
Dialog 1: Salut
Dialog 2: les
Dialog 3: filles.


Enjoy,

Emile



PS: if there is room to improve these handlers, please, share.
_______________________________________________
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: Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
  • Next by Date: Re: How can I format an integer ?
  • Previous by thread: Re: Ma always said: there is a time to take and a time to give [Mid(Source, Start, End)]
  • Next by thread: Re: Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
  • Index(es):
    • Date
    • Thread