nchar2 {lazy.tools}R Documentation

Count the number of characters using bytes, not characters, as the unit.

Description

Count the number of characters using bytes, not characters, as the unit.

Usage

nchar2(x)

Arguments

x

A string

Details

About rawToChar and charToRaw functions:
To get the raw expression of character, use
raw <- charToRaw(paste(c(0:9," ",letters,LETTERS),collapse=""))
To get the numeric equivalent of raw, use
num <- as.numeric(raw) .
To recover the original characters, use
char <- rawToChar( as.raw(num) ) .

Value

A number.

Examples


# A string consisting of single and double byte characters
nza=c(97,98,130,131,100,101,130,134,130,135,104)
za=rawToChar(as.raw(nza))

# location of the double byte characters
nchar(za)
is.DBCS(za)
Print( nchar(za), length(charToRaw(za)), nchar2(za) )
Print( nchar(za)+sum(is.DBCS(za)) )


[Package lazy.tools version 0.1.3 Index]