[REBOL] Re: Extract substring using offsets?
From: bo:rebol at: 16-Mar-2001 10:01
Kevin,
This should do it for you:
>> a: "abcdefghijklmnopqrstuvwxyz"
== "abcdefghijklmnopqrstuvwxyz"
>> copy/part at a 6 10
== "fghijklmno"
I hope this helps!
-Bo
On 16-Mar-2001/9:06:23-8:00, [kevin_kelleher--non--hp--com] wrote:
>Is there a way in Rebol to extract a substring using offsets?
>For example, if I have a string 100 characters long, and
>I want to get characters 25-50, what can I do?
>
>If there is a simple positive answer to that question,
>you can stop here. If not, read the following:
>
>To put this question in context, what I'm trying to do is
>extract a table block out of an html page. What I do is
>this:
>----------------------------------------------------------------------------
>-----------
>; --- read the page into a variable
>
>ad: read %index.html
>
>; --- get the offsets on the open-table tags
>
>htmlTables: make block! 40
>parse ad [any [to "<table" mark: thru ">"
> (append htmlTables index? mark
> append htmlTables "+")]
>]
>
>; --- get the offsets for the close-table tags
>
>parse ad [any [to "</table" mark: thru ">"
> (append htmlTables index? mark
> append htmlTables "-")]
>]
>
>; --- order them by offset
>
>sort/skip htmlTables 2
>
>; --- get the seventh open-table tag (it just happens to be the one I want)
>
>openTagCount: 0
>while [openTagCount < 7] [
> openTable: copy/part htmlTables 2
> remove/part htmlTables 2
> if openTable/2 = "+" [ openTagCount: openTagCount + 1 ]
>]
>
>; --- get the corresponding close tag (remember that tags can be nested)
>
>openTagCount: 1
>while [openTagCount > 0] [
> closeTable: copy/part htmlTables 2
> remove/part htmlTables 2
> either closeTable/2 = "+"
> [ openTagCount: openTagCount + 1 ]
> [ openTagCount: openTagCount - 1 ]
>]
>
>----------------------------------------------------------------------------
>------------------
>
>Okay, so now I have the offsets; can I do anything with them?
>Do I need to take a different approach?
>
>Kevin Kelleher
>
>--
>To unsubscribe from this list, please send an email to
>[rebol-request--rebol--com] with "unsubscribe" in the
>subject, without the quotes.
>
--
Bohdan "Bo" Lechnowsky
REBOL Adventure Guide
REBOL Technologies 707-467-8000 (http://www.rebol.com)
The Official Source for REBOL Books (http://www.REBOLpress.com)