is.DBCS {lazy.utf8}R Documentation

Checks if the Characters in a String are Multi Byte Characters.

Description

Checks if the Characters in a String are Multi Byte Characters.

Usage

is.DBCS(x)

is.MBCS(x)

Arguments

x

String vector

Details

Locale of your Windows machine can be obtained by the following:

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;

version
Sys.getlocale()


T check the character encoding, use: Encoding(char). The result will be UTF-8 or unknown meaning system encoding.

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

Hex numbers used to express raw expression can be bypassed by using
num <- char2num(char)
char <- num2char(num)

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.

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))))



[Package lazy.utf8 version 0.1.4 Index]