Charles:
> Suppose I only want characters 2 through 5? Or 3 until the end? Or I
> want
> to remove those selections? Personally, I have a hard time working with
> series! with next and skip and tail and so forth. A pointer to a list
> element
> which I cannot see irritates me.
One way is to define some basic-inspired functions:
left: func [data len [Integer!]] [
copy/part data len
]
right: func [data len [Integer!]] [
skip data ((length? data) - len)
]
mid: func [data start [Integer!] end [Integer!]] [
copy/part skip data (start - 1) end
]
They work on strings:
>> left "abcdef" 3
== "abc"
>> right "abcdef" 3
== "def"
>> mid "abcdef" 2 3
== "bcd"
>>
They work on some non-string data types too:
>> left to-binary 233 1
== #{32}
>> left to-binary 12345 1
== #{31}
>> right [1 2 3 4 5] 3
== [3 4 5]
>> if (right %file-name.txt 4) = %.txt [print "text file"]
text file
And they are reasonably error-trapped and fail-soft straight out the box
(though they'd need some beefing up in real life):
>> left "12345" 99
== "12345"
>> left "12345" 0
== ""
>> mid "12345" 0 0
== ""
>> left "12345" -3
== ""
>> left "12345" 5.6
** Script Error: left expected len argument of type: integer
** Near: left "12345" 5.6
Sunanda.
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.