substr2 {lazy.tools}R Documentation

Substr using bytes, not characters, as the unit.

Description

Substr using bytes, not characters, as the unit.

Substr sing bytes, not characters, as the unit.

Usage

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

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

Arguments

x

A string vector

start

The first location

stop

The last location

x

A string vector

start

The first location

stop

The last location

Details

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, substr2(x,n,n) is invalid.
Consult is.DBCS(x) and use with caution.

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

Value

A vector consisting of the substrings of the input vector.

Examples


# 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.
substr2(za,1,4)


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

# 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.
substr2(za,1,4)


[Package lazy.tools version 0.1.3 Index]