Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Extract substring using offsets?

From: kevin_kelleher:non:hp at: 16-Mar-2001 9:06

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