Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get text between two substrings



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:
http://lists.apple.com/mailman/options/applescript-users/email@hidden


This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.