Re: [S] delimiting strings

Alan Zaslavsky (zaslavsk@hcp.med.harvard.edu)
Wed, 21 Oct 1998 08:03:04 -0400 (EDT)


Slightly more than a one-liner (for legibility):

delimit_function(st)
{
if(length(st) != 1) stop("works only on a single string")
### blank front and back simplifies things later
st_paste(" ",st," ",sep="")
len_nchar(st)
## for generality, define any set of whitespace characters
blank_!!match(substring(st,1:len,1:len),c(" ","\t"),0)
start_(2:len)[diff(blank)==-1]
end_(2:len-1)[diff(blank)==1]
substring(st,start,end)
}

----- Begin Included Message -----

Date: Wed, 21 Oct 1998 12:38:00 +0100
From: "sinclair, andrew (MIP London)" <asinclair@edfman.co.uk>
Subject: [S] delimiting strings
To: s-news <s-news@wubios.wustl.edu>

Dear Splus-ers,

Now I would like to be able to do :

> delimit(tmp, sep=" ")
[1] "Hello" "World" "!!"

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news