% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/UTF8pgm.R
\name{is.DBCS}
\alias{is.DBCS}
\alias{is.MBCS}
\title{Checks if the Characters in a String are Multi Byte Characters.}
\usage{
is.DBCS(x)

is.MBCS(x)
}
\arguments{
\item{x}{String vector}
}
\value{
A logical vector or list of logical vectors indicating if
each character in the input string vector is a multi byte chractor or not.
}
\description{
Checks if the Characters in a String are Multi Byte Characters.
}
\details{
Locale of your Windows machine can be obtained by the following:
\preformatted{
shell("ver")
shell("PowerShell  Get-WinSystemLocale")
shell("chcp > chcp.txt")  # chcp.txt will be created somewhere.
strsplit(readLines("chcp.txt")," ")[[1]][3]
}
Code 923 means Shift-JIS.

Version and locale of R can be obtained as follows;
\preformatted{
version
Sys.getlocale()
}
\cr
T check the character encoding, use: \code{Encoding(char)}.
The result will be UTF-8 or unknown meaning system encoding.
\cr

About rawToChar and charToRaw functions: \cr
To get the raw expression of character, use\cr
 \code{ char <- paste(c(0:9," ",letters,LETTERS),collapse="")}
 \code{ raw <- charToRaw(char) }\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
\cr
Hex numbers used to express raw expression can be bypassed by using \cr
 \code{num <- char2num(char)} \cr
 \code{char <- num2char(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 in a string
is.DBCS(za)

# Pick up the single byte characters.
strsplit(za,"")[[1]][!is.DBCS(za)]
# Pick up the multi byte characters.
strsplit(za,"")[[1]][is.DBCS(za)]

# strsplit changes the encoding from Shift-JIS (double byte) to UTF-8.
Encoding(strsplit(za,"")[[1]])
Encoding(substring(za,1:nchar(za),1:nchar(za)))
unlist(nbyte(strsplit(za,"")[[1]]))
unlist(nbyte(substring(za,1:nchar(za),1:nchar(za))))


}
