From murdoch at stats.uwo.ca  Tue Aug  7 23:49:02 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 07 Aug 2007 17:49:02 -0400
Subject: [Rd] Embedded nuls in strings
In-Reply-To: <46B8DEF0.3030602@fhcrc.org>
References: <46B8DEF0.3030602@fhcrc.org>
Message-ID: <46B8E8CE.1060509@stats.uwo.ca>

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



[Rd] Embedded nuls in strings
Duncan Murdoch