Mailing Lists: Apple Mailing Lists

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

Re: Get text between two substrings



"Joseph Weaks" wrote:

> On Jun 30, 2005, Gary (Lists) wrote:
> 
>> "Joseph Weaks" wrote:
>> 
>>> Given a string, what is a good do shell script one-liner to grab the
>>> text in between two sub-strings?
>> 
>> ... grab an HTML comment ...
>> 
> No no no no... sorry. I shouldn't have confused the issue by using tags
> in the example. I want to pull the text that falls between to random
> types of strings. Use this example:
> 
> set theString to "Foo I'm all that remains Bar"


>> On Jun 30, 2005, "Joseph Weaks" wrote:
>> 
>> Would someone recommend a pure Applescript method (offset or TIDs)?

To return the text between 'Foo ' and ' Bar', one could:

set t to "Foo I'm all that remains Bar"
set tClip to item 1 of split({" Bar"}, (the rest of split({"Foo "}, t) as
string)) -- or Unicode text
to split(needle,haystack)
    set oTIDs to the text item delimiters
    set the text item delimiters to needle
    set hay to (text items of haystack)
    set the text item delimiters to oTIDs
    return hay -- a list
end split

--> "I'm all that remains"
--
Gary

 _______________________________________________
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

References: 
 >Re: Get text between two substrings (From: Joseph Weaks <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.