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
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.
[REBOL] Extract substring using offsets?
KELLEHER,KEVIN (Non-HP-Roseville,ex1) Fri, 16 Mar 2001 08:57:18 -0800
- [REBOL] Re: Extract substring using ... KELLEHER,KEVIN (Non-HP-Roseville,ex1)
- [REBOL] Re: Extract substring u... Ryan Cole
- [REBOL] Re: Extract substring u... sterling
- [REBOL] Re: Extract substring u... Dick Whiting
