Now, I have “Left(StringSource, CharCount)” and “Right(StringSource, CharCount)”
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