Home   Archive   Permalink

Cupy a part of a string

Sorry, I guess this is extreme simple, but I couldn't found a answer for this.
I simply like to take a part of a string and do a copy to another variable.
I have ONLY the position as a number of the beginning of the sequence to copy, no string. And as well the length of the sequence to copy as number only.
Is this possible without doing a loop? A loop would be way to slow. The data to process can become VERY big.
Best rgds,

posted by:   Holger       25-Aug-2011/18:15:37-7:00

variable: copy/part "This String" 5
== "This "

posted by:   Bert       26-Aug-2011/2:47:41-7:00

Well in this case, I would have only the /first/ five chars. So I would need to /navigate/ to the specific position, before I can get my string.
Is there a way to tell rebol the beginning /and/ the length in only one step?
Best rgds,

posted by:   Holger       26-Aug-2011/17:16:52-7:00

Try AT,
     >> t: "abcdefghijklm"
     == "abcdefghijklm"
     >> copy/part at t 5 3
     == "efg"
Means copy 3 chars from t starting AT char 5.

posted by:   Endo       26-Aug-2011/18:39:01-7:00

Or make it a function:
substr: func [arg [series!] start length][
    copy/part at arg start length
>> substr "test" 2 3
== est

posted by:   Endo       26-Aug-2011/20:28:33-7:00

Thanx a lot!!!
Best rgds,
Holger :)

posted by:   Holger       26-Aug-2011/21:01:14-7:00