Get text between two substrings
Get text between two substrings
- Subject: Get text between two substrings
- From: Joseph Weaks <email@hidden>
- Date: Thu, 30 Jun 2005 02:31:36 -0500
Given a string, what is a good do shell script one-liner to grab the
text in between two sub-strings? In other words:
set theString to "<!-- Begin -->My very excellent mother just served us
nine pies<!-- End -->"
set newString to do shell script "echo '" & theString & "' | perl
something '<!-- Begin -->' something '<!-- End -->'"
-- My very excellent mother just served us nine pies
Would someone recommend a pure Applescript method (offset or TIDs)?
I've been using this handler I made, but I think it's slow:
on trimContent(theString, theStart, theEnd)
-- if theStart or theEnd is an integer, then it trims at those
characters, otherwise, it assumes each a string to be used as an offset
if (class of theStart) ≠ integer then
set theOffset to (offset of theStart in theString)
if theOffset = 0 then return 0
set theStart to (theOffset + (length of theStart))
end if
if (class of theEnd) ≠ integer then
set theOffset to (offset of theEnd in theString)
if theOffset = 0 then return 0
set theEnd to (theOffset - 1)
end if
set theString to text theStart thru theEnd of theString
end trimContent
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden