nchar2 {lazy.utf8} | R Documentation |
Count the number of characters using bytes, not characters, as the unit.
nchar2(x)
x |
A string |
This function is equivalent to native nchar function with type="byte" option.
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) )
.
A number or a numeric vector.
# 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))