[REBOL] Re: Newbie Q. wrt Strings
From: carl:cybercraft at: 19-May-2001 1:00
Hi Patel,
On 18-May-01, Patel, Sanjay wrote:
> Hi,
> I have just started using Rebol. btw it is great!
> My query is if I have a string say
> data: "this is a test no 2"
> how do I manipulate the string so that I am left with the number 2.
> Or pull out the number 2 into another string/integer?
Strings are series, like blocks, and so you can play with them in much
the same way as with blocks. Thus...
>> data: "this is a test no 2"
== "this is a test no 2"
>> last data
== #"2"
>> to-string last data
== "2"
>> n: to-integer to-string last data
== 2
>> ? n
N is an integer of value: 2
The need for the "to-integer to-string" above is because to-integer on
a char! datatype returns its ASCII value.
Another way to get at your number...
>> find data "no"
== "no 2"
>> pos: index? find data "no"
== 16
>> num: skip data pos - 1
== "no 2"
>> ? num
NUM is a string of value: "no 2"
> I have tried using arrays but with no results (Arrays/Blocks).
> Any help would be appreciated!!
> SP
--
Carl Read
[carl--cybercraft--co--nz]