% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/UTF8pgm.R
\name{nchar2}
\alias{nchar2}
\title{Count the number of characters using bytes, not characters, as the unit.}
\usage{
nchar2(x)
}
\arguments{
\item{x}{A string}
}
\value{
A number or a numeric vector.
}
\description{
Count the number of characters using bytes, not characters, as the unit.
}
\details{
This function is equivalent to native nchar function with type="byte"
option.


About rawToChar and charToRaw functions: \cr
To get the raw expression of character, use\cr
\code{ raw <- charToRaw(paste(c(0:9," ",letters,LETTERS),collapse="")) }\cr
To get the numeric equivalent of raw, use\cr
\code{ num <- as.numeric(raw) }.\cr
To recover the original characters, use\cr
\code{ char <- rawToChar( as.raw(num) ) }.\cr
}
\examples{
# A string consisting of single and multi byte characters
# The 3rd, 6th and 7th characters are uppercase Zenkaku Romans.
{if( regexpr("utf8",Sys.getlocale (category = "LC_CTYPE")) > 0 )
 nza <- c(97, 98, 239, 188, 163, 100, 101, 239, 188, 166, 239, 188, 167, 104)
else
 nza <- c(97,98,130,98,100,101,130,101,130,102,104)}
za <- rawToChar(as.raw(nza))
# za <- num2char(nza)

# location of the multi byte characters
nchar(za)
is.DBCS(za)
printm( nchar(za), length(charToRaw(za)), nchar2(za) )
printm(unlist(strsplit(za,"")),nbyte(za),is.DBCS(za))


}
