[Rd] Embedded nuls in strings
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Aug 7 23:49:02 CEST 2007
On 07/08/2007 5:06 PM, Herve Pages wrote:
> Hi,
>
> ?rawToChar
> 'rawToChar' converts raw bytes either to a single character string
> or a character vector of single bytes. (Note that a single
> character string could contain embedded nuls.)
>
> Allowing embedded nuls in a string might be an interesting experiment but it
> seems to cause some troubles to most of the string manipulation functions.
>
> A string with an embedded 0:
>
> raw0 <- as.raw(c(65:68, 0 , 70))
> string0 <- rawToChar(raw0)
>
>> string0
> [1] "ABCD\0F"
>
> nchar() should return 6:
>> nchar(string0)
> [1] 4
You don't state your R version. The default type of counting in nchar()
has recently changed from "bytes" (where 6 is correct) to "chars" (where
4 is correct).
Duncan Murdoch
More information about the R-devel
mailing list