Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stri_numbytes

Count the Number of Bytes


Description

Counts the number of bytes needed to store each string in the computer's memory.

Usage

stri_numbytes(str)

Arguments

str

character vector or an object coercible to

Details

Often, this is not the function you would normally use in your string processing activities. See stri_length instead.

For 8-bit encoded strings, this is the same as stri_length. For UTF-8 strings, the returned values may be greater than the number of code points, as UTF-8 is not a fixed-byte encoding: one code point may be encoded by 1-4 bytes (according to the current Unicode standard).

Missing values are handled properly.

The strings do not need to be re-encoded to perform this operation.

The returned values do not include the trailing NUL bytes, which are used internally to mark the end of string data (in C).

Value

Returns an integer vector of the same length as str.

See Also

Other length: stri_isempty(), stri_length(), stri_width()

Examples

stri_numbytes(letters)
stri_numbytes(c('abc', '123', '\u0105\u0104'))

## Not run: 
# this used to fail on Windows, as there was no native support for 4-bytes
# Unicode characters; see, however, stri_escape_unicode():
stri_numbytes('\U7fffffff') # compare stri_length('\U7fffffff')

## End(Not run)

stringi

Character String Processing Facilities

v1.6.1
file LICENSE
Authors
Marek Gagolewski [aut, cre, cph] (<https://orcid.org/0000-0003-0637-6028>), Bartek Tartanus [ctb], and others (stringi source code); IBM, Unicode, Inc. and others (ICU4C source code, Unicode Character Database)
Initial release
2021-05-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.