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

Extract substring using offsets?

 [1/5] 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

 [2/5] from: ryanc::iesco-dms::com at: 16-Mar-2001 9:34


This is basicly a copy of the BASIC mid$ function... mid-string: func [string offset length] [copy/part at string offset length] --Ryan KELLEHER,KEVIN (Non-HP-Roseville,ex1) wrote:

 [3/5] 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
<<quoted lines omitted: 46>>
>[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)

 [4/5] from: sterling:rebol at: 16-Mar-2001 11:05


> 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?
copy/part at str 25 25
> If there is a simple positive answer to that question, > you can stop here. If not, read the following:
Stopping. Sterling

 [5/5] from: dwhiting:europa at: 16-Mar-2001 13:26


On Fri, 16 Mar 2001, KELLEHER,KEVIN (Non-HP-Roseville,ex1) 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? >
substr: copy/part skip stringin 24 26 Dick #==============================================# Homepage: http://www.europa.com/~dwhiting/ IRC: Satyre on #AmigaCafe #==============================================#

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted