substrDBCS {lazy.utf8}R Documentation

Substr Using Column Location as the Unit for ASCII or DBCS characters

Description

Substr Using Column Location as the Unit for ASCII or DBCS characters

Usage

substrDBCS(x, start, stop = max(nchar(x, type = "byte")))

Arguments

x

A string vector

start

The first location

stop

The last location

Details

This is for strictly DUOBLE byte characters. NOT for UTF-8 characters. For strictly double byte characters, this is faster than susbtr2.

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


If the n-th byte is the beginning or the ending location of
a double byte character, substrDBCS(x,n,n) is invalid.
Consult is.DBCS(x) and use with caution.

Value

A vector consisting of the substrings of the input vector.

Examples

## Not run: 

# Below causes error if you are using R 4.2.0 or above.

# 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))
Print(za)
# location of the double byte characters
is.DBCS(za)
# The first to the fourth characters
substr(za,1,4)
# The characters stored in the first to the fourth bytes of za.
substrDBCS(za,1,4)


## End(Not run)


[Package lazy.utf8 version 0.1.4 Index]